Print this page
Split Close
Expand all
Collapse all
          --- /workspace/du105637/oscposthot/webrev/usr/src/cmd/ha-services/gds-agents/PostgreSQL/functions.ksh-
          +++ functions.ksh
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13  # When distributing Covered Code, include this CDDL HEADER in each
  14   14  # file and include the License file at usr/src/CDDL.txt.
  15   15  # If applicable, add the following below this CDDL HEADER, with the
  16   16  # fields enclosed by brackets [] replaced with your own identifying
  17   17  # information: Portions Copyright [yyyy] [name of copyright owner]
  18   18  #
  19   19  # CDDL HEADER END
  20   20  #
  21   21  
  22   22  #
  23      -# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
       23 +# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24   24  # Use is subject to license terms.
  25   25  #
  26   26  
  27      -#ident  "%Z%%M% %I%     %E% SMI"
       27 +# ident   "%Z%%M% %I%     %E% SMI"
  28   28  
  29   29  PKG=SUNWscPostgreSQL
  30   30  METHOD=`basename $0`
  31   31  TASK_COMMAND=""
  32   32  
  33   33  ZONENAME=/usr/bin/zonename
  34   34  DIRNAME=/usr/bin/dirname
  35   35  
  36   36  SCLOGGER=/usr/cluster/lib/sc/scds_syslog
  37   37  PMFADM=/usr/cluster/bin/pmfadm
↓ open down ↓ 12 lines elided ↑ open up ↑
  50   50  IPCRM=/usr/bin/ipcrm
  51   51  ECHO=/usr/bin/echo
  52   52  TR=/usr/bin/tr
  53   53  SU=/usr/bin/su
  54   54  RM=/usr/bin/rm
  55   55  ZLOGIN=/usr/sbin/zlogin
  56   56  TEST=/usr/bin/test
  57   57  PING=/usr/sbin/ping
  58   58  SED=/usr/bin/sed
  59   59  IFCONFIG=/usr/sbin/ifconfig
       60 +SSH=/usr/bin/ssh
       61 +SSH_AGENT=/usr/bin/ssh-agent
       62 +PKILL=/usr/bin/pkill
       63 +WC=/usr/bin/wc
       64 +SLEEP=/usr/bin/sleep
       65 +TOUCH=/usr/bin/touch
       66 +CHOWN=/usr/bin/chown
       67 +CP=/usr/bin/cp
  60   68  
  61   69  get_fmri_parameters ()
  62   70  {
  63   71  
  64   72  # extract the smf properties, you need to call your agent commands
  65   73  
  66   74          debug_message "Function: get_fmri_parameters - Begin "
  67   75          ${SET_DEBUG}
  68   76  
  69   77  # Resource name
↓ open down ↓ 182 lines elided ↑ open up ↑
 252  260  PGHOST=${PGHOST}
 253  261  PGLOGFILE=${PGLOGFILE}
 254  262  LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
 255  263  ENVSCRIPT=${ENVSCRIPT}
 256  264  SCDB=${SCDB}
 257  265  SCUSER=${SCUSER}
 258  266  SCTABLE=${SCTABLE}
 259  267  SCPASS=${SCPASS}
 260  268  NOCONRET=${NOCONRET}
 261  269  
      270 +# The following parameters need to be configured only if logfile shipping is configured to ship
      271 +# the PosgreSQL WAL logs between a designated primary and a designated standby resource.
      272 +# They need to be configured only on the primary.
      273 +
      274 +#        STDBY_RS  The resource name of the PostgreSQL standby resource.
      275 +#        STDBY_RG  The resource group name of the PostgreSQL standby resource group.
      276 +#      STDBY_USER  User which is the owner of the standby postgres database.
      277 +#      STDBY_HOST  Resolvable name of the standby host or the standby zone, 
      278 +#                  this name has to be reachable via ssh.
      279 +#   STDBY_PARFILE  The standbys postgres parameter file to get the rest of the necessary parameters.
      280 +#   STDBY_PING     The number of of packets the primary uses to ping the standby host. If this variable is
      281 +#                  empty, it will be set to 5 packets.
      282 +#   ROLECHG_RS     The rolechangers resource name.
      283 +#  SSH_PASSDIR     A directory where the ssh passphrase is stored in a the file <resourcename>-phrase.
      284 +#                  This parameter is needed only if you configured WAL file shipping and secured your
      285 +#                  ssh key with a passphrase.
      286 +#                  Leave it undefined if the passprase is empty.
      287 +#
      288 +# If you configure the logfile shipping in a shared nothing topology, do not set the LH parameter.
      289 +#
      290 +# Configure the following paramters on the primary host.
      291 +
      292 +STDBY_RS=${STDBY_RS}
      293 +STDBY_RG=${STDBY_RG}
      294 +STDBY_USER=${STDBY_USER}
      295 +STDBY_HOST=${STDBY_HOST}
      296 +STDBY_PARFILE=${STDBY_PARFILE}
      297 +STDBY_PING=${STDBY_PING}
      298 +#
      299 +# Configure the following paramter on the standby host.
      300 +#
      301 +ROLECHG_RS=${ROLECHG_RS}
      302 +#
      303 +# Configure the following parameter on both hosts.
      304 +#
      305 +SSH_PASSDIR=${SSH_PASSDIR}
      306 +
 262  307  EOF
 263  308          if [ $? -ne 0 ]
 264  309          then
 265  310                  ${ECHO} "ERROR: could not create the temporary parameter file ${pfile_tmp}"
 266  311                  return 1
 267  312          fi
 268  313  
 269  314          # create the parameter file either in the global or in the prepared target zone
 270  315  
 271  316          if [ -n "${target_zone}" ]
↓ open down ↓ 32 lines elided ↑ open up ↑
 304  349                          RESOURCE)
 305  350                          if [ -z "${RESOURCE}" ]; then
 306  351                                  # SCMSGS
 307  352                                  # @explanation
 308  353                                  # The start, stop or probe command requires an
 309  354                                  # option which is not set.
 310  355                                  # @user_action
 311  356                                  # Fix the start, stop or probe command in the
 312  357                                  # SUNW.gds resource.
 313  358                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 314      -                                "Function: validate_options: %s Option %s not set" \
 315      -                                "${METHOD}" "-R"
      359 +                                        "Function: validate_options: %s Option %s not set" \
      360 +                                        "${METHOD}" "-R"
 316  361                                  return 1
 317  362                          fi;;
 318  363  
 319  364                          RESOURCEGROUP)
 320  365                          if [ -z "${RESOURCEGROUP}" ]; then
 321  366                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 322      -                                "Function: validate_options: %s Option %s not set" \
 323      -                                "${METHOD}" "-G"
      367 +                                        "Function: validate_options: %s Option %s not set" \
      368 +                                        "${METHOD}" "-G"
 324  369                                  return 1
 325  370                          fi;;
 326  371  
 327  372                          PARFILE)
 328  373                          if [ -z "${PARFILE}" ]; then
 329  374                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 330      -                                "Function: validate_options: %s Option %s not set" \
 331      -                                "${METHOD}" "-P"
      375 +                                        "Function: validate_options: %s Option %s not set" \
      376 +                                        "${METHOD}" "-P"
 332  377                                  return 1
 333  378                          fi;;
 334  379                  esac
 335  380          done
 336  381  
 337  382          debug_message "Function: validate_options - End"
 338  383  }
 339  384  
 340  385  validate()
 341  386  {
↓ open down ↓ 24 lines elided ↑ open up ↑
 366  411  
 367  412                          if [ -z "${USER}" ]; then
 368  413                                  # SCMSGS
 369  414                                  # @explanation
 370  415                                  # A mandatory variable is unset in the
 371  416                                  # parameter file.
 372  417                                  # @user_action
 373  418                                  # Fix the parameter file and provide a value
 374  419                                  # for the variable in the parameter file
 375  420                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 376      -                                "Function: validate: The %s variable is not set, but it is required" \
 377      -                                "USER"
      421 +                                        "Function: validate: The %s variable is not set, but it is required" \
      422 +                                        "USER"
 378  423                                  rc_validate=1
 379  424                          else
 380  425                                  id ${USER} >/dev/null 2>&1
 381  426                                  if [ $? -ne 0 ]; then
 382  427                                          # SCMSGS
 383  428                                          # @explanation
 384  429                                          # The user mentioned in the parameter
 385  430                                          # file is not defined in the OS.
 386  431                                          # @user_action
 387  432                                          # Fix the parameter file and provide
↓ open down ↓ 7 lines elided ↑ open up ↑
 395  440                                          debug_message "Function: validate - USER OK"    
 396  441                                  fi
 397  442                          fi;;
 398  443  
 399  444                          PGROOT)
 400  445  
 401  446                          # Test the PG Root variable
 402  447                                
 403  448                          if [ -z "${PGROOT}" ]; then
 404  449                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 405      -                                "Function: validate: The %s variable is not set, but it is required" \
 406      -                                "PGROOT"
      450 +                                        "Function: validate: The %s variable is not set, but it is required" \
      451 +                                        "PGROOT"
 407  452                                  rc_validate=1
 408  453                          else
 409  454                                  if [ ! -d ${PGROOT} ]; then
 410  455                                          # SCMSGS
 411  456                                          # @explanation
 412  457                                          # The directory mentioned in the
 413  458                                          # parameter file for the PGROOT or
 414  459                                          # PGDATA variable does not exist.
 415  460                                          # @user_action
 416  461                                          # Fix the parameter file and provide
 417  462                                          # an existing directoy for the
 418  463                                          # variable PGROOT or PGDATA.
 419  464                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 420      -                                        "Function: validate: Directory %s does not exist, an existing directory is required" \
 421      -                                        "${PGROOT}"
      465 +                                                "Function: validate: Directory %s does not exist, an existing directory is required" \
      466 +                                                "${PGROOT}"
 422  467                                          rc_validate=1
 423  468                                  fi
 424  469  
 425  470                                  # test if it is a postgres installation
 426  471  
 427  472                                  if [ ! -f ${PGROOT}/bin/pg_ctl ]
 428  473                                  then
 429  474                                          # SCMSGS
 430  475                                          # @explanation
 431  476                                          # The directory mentioned in the
 432  477                                          # PGROOT variable does not contain the
 433  478                                          # PostgreSQL binaries in its bin
 434  479                                          # directory.
 435  480                                          # @user_action
 436  481                                          # Provide the directory which does
 437  482                                          # contain at least the PostgreSQL
 438  483                                          # binaries in the path ./bin.
 439  484                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 440      -                                        "Function: validate: Directory %s does not contain the PostgreSQL binaries" \
 441      -                                        "${PGROOT}"
      485 +                                                "Function: validate: Directory %s does not contain the PostgreSQL binaries" \
      486 +                                                "${PGROOT}"
 442  487                                          rc_validate=1
 443  488                                  else 
 444  489                                          debug_message "Function: validate - PGROOT OK"  
 445  490                                  fi
 446  491                          fi;;
 447  492  
 448  493                          PGDATA)
 449  494  
 450  495                          # Test the PG Data variable
 451  496                                
 452  497                          if [ -z "${PGDATA}" ]; then
 453  498                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 454      -                                "Function: validate: The %s variable is not set, but it is required" \
 455      -                                "PGDATA"
      499 +                                        "Function: validate: The %s variable is not set, but it is required" \
      500 +                                        "PGDATA"
 456  501                                  rc_validate=1
 457  502                          else
 458  503                                  if [ ! -d ${PGDATA} ]; then
 459  504                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 460      -                                        "Function: validate: Directory %s does not exist, an existing directory is required" \
 461      -                                        "${PGDATA}"
      505 +                                                "Function: validate: Directory %s does not exist, an existing directory is required" \
      506 +                                                "${PGDATA}"
 462  507                                          rc_validate=1
 463  508                                  fi
 464  509  
 465  510                                  # test if it is a postgres database cluster
 466  511  
 467  512                                  if [ ! -f ${PGDATA}/postgresql.conf ]
 468  513                                  then
 469  514                                          # SCMSGS
 470  515                                          # @explanation
 471  516                                          # A directory is specified in the
 472  517                                          # PGDATA variable which does not
 473  518                                          # contain a postgresql.conf file.
 474  519                                          # @user_action
 475  520                                          # Specify a directory in the PGDATA
 476  521                                          # variable in the parmeter file, which
 477  522                                          # contains the postgresql.conf file.
 478  523                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 479      -                                        "Function: validate: Directory %s does not contain the PostgreSQL configuration files" \
 480      -                                        "${PGDATA}"
      524 +                                                "Function: validate: Directory %s does not contain the PostgreSQL configuration files" \
      525 +                                                "${PGDATA}"
 481  526                                          rc_validate=1
 482  527                                  else 
 483  528                                          debug_message "Function: validate - PGDATA OK"  
 484  529                                  fi
 485  530                          fi;;
 486  531  
 487  532                          PGPORT) 
 488  533  
 489  534                          # Test the PG Port variable
 490  535                                
 491  536                          if [ -z "${PGPORT}" ]; then
 492  537                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 493      -                                "Function: validate: The %s variable is not set, but it is required" \
 494      -                                "PGPORT"
      538 +                                        "Function: validate: The %s variable is not set, but it is required" \
      539 +                                        "PGPORT"
 495  540                                  rc_validate=1
 496  541                          else
 497  542  
 498  543                                  # test if the port is numeric
 499  544  
 500  545                                  if  ! let x=${PGPORT} >/dev/null 2>&1
 501  546                                  then
 502  547                                          # SCMSGS
 503  548                                          # @explanation
 504  549                                          # In the parameter file, there is a
 505  550                                          # non numeric character in the value
 506  551                                          # for the PGPORT variable.
 507  552                                          # @user_action
 508  553                                          # Fix the PGPORT variable in the
 509  554                                          # parameter file.
 510  555                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 511      -                                        "Function: validate: Port %s is not numeric" \
 512      -                                        "${PGPORT}"
      556 +                                                "Function: validate: Port %s is not numeric" \
      557 +                                                "${PGPORT}"
 513  558                                          rc_validate=1
 514  559                                  else 
 515  560                                          debug_message "Function: validate - PGPORT OK"  
 516  561                                  fi
 517  562                          fi;;
 518  563  
 519  564                          PGHOST)
 520  565  
 521  566                          # test the PGHOST variable ony if it is defined
 522  567  
↓ open down ↓ 10 lines elided ↑ open up ↑
 533  578                                          if [ ! -d "${PGHOST}" ]
 534  579                                          then
 535  580                                                  
 536  581                                                  # SCMSGS
 537  582                                                  # @explanation
 538  583                                                  # The directory specified in the PGHOST variable does not
 539  584                                                  # exist.
 540  585                                                  # @user_action
 541  586                                                  # Create the directory. None if it was a lost mount.
 542  587                                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 543      -                                                "Function: validate - Directory for the socket file %s does not exist" \
 544      -                                                "${PGHOST}"
      588 +                                                        "Function: validate - Directory for the socket file %s does not exist" \
      589 +                                                        "${PGHOST}"
 545  590                                                  rc_validate=1
 546  591                          
 547  592                                          else
 548  593                                                  debug_message "Function: validate - PGHOST OK"  
 549  594                                          fi
 550  595                                  
 551  596                                  else
 552  597                                          if ! ${GETENT} hosts ${PGHOST} >/dev/null 2>&1
 553  598                                          then
 554  599                                                  
 555  600                                                  # SCMSGS
 556  601                                                  # @explanation
 557  602                                                  # The host specified in the PGHOST variable is not
 558  603                                                  # resolvable.
 559  604                                                  # @user_action
 560  605                                                  # Create the the host entry in /etc/hosts.
 561  606                                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 562      -                                                "Function: validate - The host %s is not resolvable" \
 563      -                                                "${PGHOST}"
      607 +                                                        "Function: validate - The host %s is not resolvable" \
      608 +                                                        "${PGHOST}"
 564  609                                                  rc_validate=1
 565  610                                                  
 566  611                                          else
 567  612                                                  debug_message "Function: validate - PGHOST resolvable"  
 568  613                                          fi
 569  614  
 570  615                                          # Validate if the address of the PGHOST variable is configured UP
 571  616                                          # on a adapter of the host. This validation works in
 572  617                                          # global zones, local zones and in failover zones.
 573  618                                          # This method was preferred over checking the dependency tree,
↓ open down ↓ 23 lines elided ↑ open up ↑
 597  642                                          if [ ${adapter_success} -ne 0 ]
 598  643                                          then
 599  644                                                  
 600  645                                                  # SCMSGS
 601  646                                                  # @explanation
 602  647                                                  # The host specified in the PGHOST variable is not
 603  648                                                  # configured up on the hosts adapters.
 604  649                                                  # @user_action
 605  650                                                  # Fix either the network configuration or the PGHOST variable
 606  651                                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 607      -                                                "Function: validate - The host %s is not configured UP on the hosts adapters" \
 608      -                                                "${PGHOST}"
      652 +                                                        "Function: validate - The host %s is not configured UP on the hosts adapters" \
      653 +                                                        "${PGHOST}"
 609  654                                                  rc_validate=1
 610  655                                          else
 611  656                                                  debug_message "Function: validate - PGHOST is configured on the nodes adapters" 
 612  657                                          fi
 613  658                                  fi
 614  659                          fi;;
 615  660  
 616  661                          PGLOGFILE)
 617  662  
 618  663                          # Test the Logfile variable
 619  664                                
 620  665                          if [ -z "${PGLOGFILE}" ]; then
 621  666                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 622      -                                "Function: validate: The %s variable is not set, but it is required" \
 623      -                                "PGLOGFILE"
      667 +                                        "Function: validate: The %s variable is not set, but it is required" \
      668 +                                        "PGLOGFILE"
 624  669                                  rc_validate=1
 625  670                          else
 626  671  
 627  672                                  # test if the directory for Logfile exists
 628  673  
 629  674                                  Logdir=`/usr/bin/dirname ${PGLOGFILE}`
 630  675                                  if [ ! -d ${Logdir} ]; then
 631  676                                          # SCMSGS
 632  677                                          # @explanation
 633  678                                          # The path to the filename variable
 634  679                                          # PGLOGFILE does not exist.
 635  680                                          # @user_action
 636  681                                          # Qualify the filename of the parameter
 637  682                                          # files PGLOGFILE variable in an
 638  683                                          # existing directory.
 639  684                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 640      -                                        "Function: validate: Directory for logfile %s does not exist, an existing directory is required" \
 641      -                                        "${PGLOGFILE}"
      685 +                                                "Function: validate: Directory for logfile %s does not exist, an existing directory is required" \
      686 +                                                "${PGLOGFILE}"
 642  687                                          rc_validate=1
 643  688                                  else 
 644  689                                          debug_message "Function: validate - PGLOGFILE OK"       
 645  690                                  fi
 646  691                          fi;;
 647  692  
 648  693                          LD_LIBRARY_PATH)
 649  694  
 650  695                          # test LD_LIBRARY_PATH if it is set
 651  696  
↓ open down ↓ 4 lines elided ↑ open up ↑
 656  701                                  then
 657  702                                          # SCMSGS
 658  703                                          # @explanation
 659  704                                          # The LD_LIBRARY_PATH is not valid to
 660  705                                          # call the postgres binary.
 661  706                                          # @user_action
 662  707                                          # Qualify the LD_LIBRARY_PATH in the
 663  708                                          # parameter file until it is
 664  709                                          # sufficient for the psql binary.
 665  710                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 666      -                                        "Function: validate: The LD_LIBRARY_PATH %s is not valid for this PostgreSQL installation" \
 667      -                                        "${LD_LIBRARY_PATH}"
      711 +                                                "Function: validate: The LD_LIBRARY_PATH %s is not valid for this PostgreSQL installation" \
      712 +                                                "${LD_LIBRARY_PATH}"
 668  713                                          rc_validate=1
 669  714                                  else 
 670  715                                          debug_message "Function: validate - LD_LIBRARY_PATH OK" 
 671  716                                  fi
 672  717                          fi;;
 673  718  
 674  719                          ENVSCRIPT) 
 675  720  
 676  721                          # test if the environment script is a syntactically valid script
 677  722                          # In the smf context it needs to be a ksh script.
↓ open down ↓ 44 lines elided ↑ open up ↑
 722  767                                                          # shell of the
 723  768                                                          # PostgreSQL user is
 724  769                                                          # korn shell
 725  770                                                          # compliant.
 726  771                                                          # @user_action
 727  772                                                          # Fix the environment
 728  773                                                          # script until it
 729  774                                                          # passes ksh -n
 730  775                                                          # scriptname.
 731  776                                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 732      -                                                        "Function: validate: The Environment script %s is not a valid korn shell script" \
 733      -                                                        "${ENVSCRIPT}"
      777 +                                                                "Function: validate: The Environment script %s is not a valid korn shell script" \
      778 +                                                                "${ENVSCRIPT}"
 734  779                                                          rc_validate=1
 735  780                                                  else 
 736  781                                                          debug_message "Function: validate - ENVSCRIPT OK"       
 737  782                                                  fi
 738  783                                          fi
 739  784                                  else
 740  785                                          # SCMSGS
 741  786                                          # @explanation
 742  787                                          # The filename specified in the
 743  788                                          # parameter files ENVSCRIPT variable
 744  789                                          # does not exist.
 745  790                                          # @user_action
 746  791                                          # Fix the parameter file and specify a
 747  792                                          # valid Environment script.
 748  793                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 749      -                                        "Function: validate: The Environment script %s does not exist" \
 750      -                                        "${ENVSCRIPT}"
      794 +                                                "Function: validate: The Environment script %s does not exist" \
      795 +                                                "${ENVSCRIPT}"
 751  796                                          rc_validate=1
 752  797                          
 753  798                                  fi
 754  799                          fi;;
 755  800  
 756  801                          SCDB) 
 757  802  
 758  803                          # Test if the test database variable is defined
 759  804                                
 760  805                          if [ -z "${SCDB}" ]; then
 761  806                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 762      -                                "Function: validate: The %s variable is not set, but it is required" \
 763      -                                "SCDB"
      807 +                                        "Function: validate: The %s variable is not set, but it is required" \
      808 +                                        "SCDB"
 764  809                                  rc_validate=1
 765  810                          else 
 766  811                                  debug_message "Function: validate - SCDB OK"    
 767  812                          fi;;
 768  813  
 769  814                          SCUSER)
 770  815  
 771  816                          # Test if the database user variable is defined
 772  817                                
 773  818                          if [ -z "${SCUSER}" ]; then
 774  819                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 775      -                                "Function: validate: The %s variable is not set, but it is required" \
 776      -                                "SCUSER"
      820 +                                        "Function: validate: The %s variable is not set, but it is required" \
      821 +                                        "SCUSER"
 777  822                                  rc_validate=1
 778  823                          else 
 779  824                                  debug_message "Function: validate - SCUSER OK"  
 780  825                          fi;;
 781  826  
 782  827                          SCTABLE)
 783  828  
 784  829                          # Test if the database table variable is defined
 785  830                                
 786  831                          if [ -z "${SCTABLE}" ]; then
 787  832                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 788      -                                "Function: validate: The %s variable is not set, but it is required" \
 789      -                                "SCTABLE"
      833 +                                        "Function: validate: The %s variable is not set, but it is required" \
      834 +                                        "SCTABLE"
 790  835                                  rc_validate=1
 791  836                          else 
 792  837                                  debug_message "Function: validate - SCTABLE OK" 
 793  838                          fi;;
 794  839  
 795  840                          NOCONRET)
 796  841  
 797  842                          # Test the No Connection return code  variable
 798  843                                
 799  844                          if [ -z "${NOCONRET}" ]; then
 800  845                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 801      -                                "Function: validate: The %s variable is not set, but it is required" \
 802      -                                "NOCONRET"
      846 +                                        "Function: validate: The %s variable is not set, but it is required" \
      847 +                                        "NOCONRET"
 803  848                                  rc_validate=1
 804  849                          else
 805  850  
 806  851                                  # test if the NOCONRET is numeric
 807  852  
 808  853                                  if  ! let x=${NOCONRET} >/dev/null 2>&1
 809  854                                  then
 810  855                                          # SCMSGS
 811  856                                          # @explanation
 812  857                                          # The value for the NOCONRET variable
 813  858                                          # contains a non numeric character.
 814  859                                          # @user_action
 815  860                                          # Fix the NOCONRET variable in the
 816  861                                          # parameter file.
 817  862                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
 818      -                                        "Function: validate: Return code for failed connections %s is not numeric" \
 819      -                                        "${NOCONRET}"
      863 +                                                "Function: validate: Return code for failed connections %s is not numeric" \
      864 +                                                "${NOCONRET}"
 820  865                                          rc_validate=1
 821  866                                  else 
 822  867                                          if [ ${NOCONRET} -gt 100 ]; then
 823  868                                                  # SCMSGS
 824  869                                                  # @explanation
 825  870                                                  # The value of the NOCONRET
 826  871                                                  # variable in the parameter
 827  872                                                  # file exeeds 100.
 828  873                                                  # @user_action
 829  874                                                  # Fix the parameter file with
 830  875                                                  # a value below 100.
 831  876                                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 832      -                                                "Function: validate: Return code for failed connections %s is greater 100" \
 833      -                                                "${NOCONRET}"
      877 +                                                        "Function: validate: Return code for failed connections %s is greater 100" \
      878 +                                                        "${NOCONRET}"
 834  879                                                  rc_validate=1
 835  880                                          else
 836  881                                                  debug_message "Function: validate - NOCONRET OK"        
 837  882                                          fi
 838  883                                  fi
 839  884                          fi;;
      885 +
      886 +                        STDBY_HOST) 
      887 +
      888 +                        # Test the standby host variable and the neccessary other variables if the standby 
      889 +                        # host variable is not set.
      890 +                              
      891 +                        if [ -n "${STDBY_HOST}" ]; then
      892 +                                if ! ${GETENT} hosts ${STDBY_HOST} >/dev/null 2>&1
      893 +                                then
      894 +                        
      895 +                                        # SCMSGS
      896 +                                        # @explanation
      897 +                                        # The host specified in the STDBY_HOST variable is not
      898 +                                        # resolvable.
      899 +                                        # @user_action
      900 +                                        # Add the host to one of your configured name services, 
      901 +                                        # so it can get listed with getent.
      902 +                                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
      903 +                                                "Function: validate - The standby host %s is not resolvable" \
      904 +                                                "${STDBY_HOST}"
      905 +                                        rc_validate=1
      906 +                                                
      907 +                                else
      908 +                                        debug_message "Function: validate - STDBY_HOST resolvable"      
      909 +                                fi
      910 +
      911 +                                # Test if all the other standby related variables are set.
      912 +                                # There will be no other validation, because it may be that the necessary
      913 +                                # resources are not up right now, and then the validation will fail without 
      914 +                                # a valid reason which is related to the parameter configuration.
      915 +
      916 +                                if [ -z "${STDBY_RS}" ]
      917 +                                then
      918 +                                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
      919 +                                                "Function: validate: The %s variable is not set, but it is required" \
      920 +                                                "STDBY_RS"
      921 +                                        rc_validate=1
      922 +                                else
      923 +                                        debug_message "Function: validate - STDBY_RS OK"
      924 +                                fi
      925 +
      926 +                                if [ -z "${STDBY_RG}" ]
      927 +                                then
      928 +                                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
      929 +                                                "Function: validate: The %s variable is not set, but it is required" \
      930 +                                                "STDBY_RG"
      931 +                                        rc_validate=1
      932 +                                else
      933 +                                        debug_message "Function: validate - STDBY_RG OK"
      934 +                                fi
      935 +
      936 +                                if [ -z "${STDBY_USER}" ]
      937 +                                then
      938 +                                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
      939 +                                                "Function: validate: The %s variable is not set, but it is required" \
      940 +                                                "STDBY_USER"
      941 +                                        rc_validate=1
      942 +                                else
      943 +                                        debug_message "Function: validate - STDBY_USER OK"
      944 +                                fi
      945 +
      946 +                                if [ -z "${STDBY_PARFILE}" ]
      947 +                                then
      948 +                                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
      949 +                                                "Function: validate: The %s variable is not set, but it is required" \
      950 +                                                "STDBY_PARFILE"
      951 +                                        rc_validate=1
      952 +                                else
      953 +                                        debug_message "Function: validate - STDBY_PARFILE OK"
      954 +                                fi
      955 +
      956 +                                if [ -n "${STDBY_PING}" ]
      957 +                                then
      958 +                                        if  ! let x=${STDBY_PING} >/dev/null 2>&1
      959 +                                        then
      960 +                                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
      961 +                                                        "Function: validate: The STDBY_PING value of %s is not numeric" \
      962 +                                                        "${STDBY_PING}"
      963 +                                                rc_validate=1
      964 +                                        else
      965 +                                                debug_message "Function: validate - STDBY_PING OK"
      966 +                                        fi
      967 +                                else
      968 +                                        # set a default of 5 packets
      969 +                                        STDBY_PING=5
      970 +                                        debug_message "Function: validate - STDBY_PING OK, it was set to 5 packets"
      971 +                                fi
      972 +
      973 +                        fi;;
 840  974                  esac
 841  975          done
 842  976  
 843  977          debug_message "Function: validate - End"
 844  978          return ${rc_validate}
 845  979  }
 846  980  
 847  981  validate_probe()
 848  982  {
 849  983          # Validate ony for non existant files or lost directories
↓ open down ↓ 11 lines elided ↑ open up ↑
 861  995          then
 862  996  
 863  997  
 864  998                  # SCMSGS
 865  999                  # @explanation
 866 1000                  # The file specified in the PARFILE variable does not
 867 1001                  # exist any more.
 868 1002                  # @user_action
 869 1003                  # Create the directory and restore the parameter file. None if it was a lost mount.
 870 1004                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 871      -                "Function: validate_probe - Directory for the parameter file %s does not exist any more, a faiover will occur" \
 872      -                "${PARFILE}"
     1005 +                        "Function: validate_probe - Directory for the parameter file %s does not exist any more, a faiover will occur" \
     1006 +                        "${PARFILE}"
 873 1007  
 874 1008                  rc_val_probe=201
 875 1009          fi
 876 1010  
 877 1011          # source the parameter file
 878 1012  
 879 1013          . ${PARFILE}
 880 1014  
 881 1015          # Check the PGHOST variable.
 882 1016          # If the PGHOST variable starts with a / then it should be a directory which contains the socket file.
↓ open down ↓ 14 lines elided ↑ open up ↑
 897 1031                          if [ ! -d "${PGHOST}" ]
 898 1032                          then
 899 1033                                  
 900 1034                                  # SCMSGS
 901 1035                                  # @explanation
 902 1036                                  # The directory specified in the PGHOST variable does not
 903 1037                                  # exist any more.
 904 1038                                  # @user_action
 905 1039                                  # Create the directory. None if it was a lost mount.
 906 1040                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 907      -                                "Function: validate_probe - Directory for the socket file %s does not exist any more, a faiover will occur" \
 908      -                                "${PGHOST}"
     1041 +                                        "Function: validate_probe - Directory for the socket file %s does not exist any more, a faiover will occur" \
     1042 +                                        "${PGHOST}"
 909 1043                                  rc_val_probe=201
 910 1044                          else
 911 1045                                  debug_message "Function: validate_probe - the directory in PGHOST exists"
 912 1046                          fi
 913 1047                  
 914 1048                  else
 915 1049  
 916 1050                          # If an address is specified, test it with ping. Initiate a failover if the address 
 917 1051                          # is unavailable.       
 918 1052                          # This needs to be done, because an unpingable address will cause the psql commands to hang
↓ open down ↓ 6 lines elided ↑ open up ↑
 925 1059  
 926 1060                          if ! ${PING} ${PGHOST} 1 >/dev/null 2>&1
 927 1061                          then
 928 1062                                  # SCMSGS
 929 1063                                  # @explanation
 930 1064                                  # The address specified in the PGHOST variable
 931 1065                                  # is unavailable.
 932 1066                                  # @user_action
 933 1067                                  # None, a failover will occur
 934 1068                                  scds_syslog -p daemon.err -t $(syslog_tag) -m \
 935      -                                "check_pgs: The host %s is not accessible, a failover will occur" \
 936      -                                "${PGHOST}"
     1069 +                                        "check_pgs: The host %s is not accessible, a failover will occur" \
     1070 +                                        "${PGHOST}"
 937 1071          
 938 1072                                  rc_val_probe=201
 939 1073                          else
 940 1074                                  debug_message "Function: validate_probe - the host in PGHOST is pingable"
 941 1075                          fi
 942 1076                  fi
 943 1077          fi
 944 1078  
 945 1079          debug_message "Function: validate_probe - End"
 946 1080          return $rc_val_probe
↓ open down ↓ 126 lines elided ↑ open up ↑
1073 1207  
1074 1208          if [ "${flag}" ]; then
1075 1209                  # SCMSGS
1076 1210                  # @explanation
1077 1211                  # Remaining IPC shared memory segments have been removed.
1078 1212                  # These segements are a leftover of the previous PostgreSQL
1079 1213                  # instance.
1080 1214                  # @user_action
1081 1215                  # None
1082 1216                  scds_syslog -p daemon.notice -t $(syslog_tag) -m \
1083      -                "All PostgreSQL non-attached IPC shared memory segments removed"
     1217 +                        "All PostgreSQL non-attached IPC shared memory segments removed"
1084 1218          fi
1085 1219  
1086 1220          if [ -n "${DEBUG}" ]
1087 1221          then
1088 1222                  debug_message "IPC Status AFTER removal of non-attached segments created by user ${User}"
1089 1223  
1090 1224                  ${IPCS} -mcopb > ${LOGFILE}
1091 1225  
1092 1226                  log_message debug ipcs
1093 1227                  $RM ${LOGFILE}
↓ open down ↓ 3 lines elided ↑ open up ↑
1097 1231  }
1098 1232  
1099 1233  start_pgs()
1100 1234  {
1101 1235          #
1102 1236          # Start PostgreSQL
1103 1237          #
1104 1238  
1105 1239          debug_message "Function: start_pgs - Begin"
1106 1240          ${SET_DEBUG}
     1241 +        SECONDS=0
1107 1242  
1108 1243          # construct the necessary redirection and source variables
1109 1244  
1110 1245          set_shell_specifics
1111 1246  
1112 1247          # Define the appropriate newtask command.
1113 1248          # The Project will be derived according to the call method,
1114 1249          # either from the smf service or from the cluster resource / resource group
1115 1250  
1116 1251          srm_function ${USER}
↓ open down ↓ 9 lines elided ↑ open up ↑
1126 1261          then
1127 1262                  LIBPATH="${ENV} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
1128 1263          fi
1129 1264  
1130 1265          PORT="PGPORT=${PGPORT}"
1131 1266          DATA="PGDATA=${PGDATA}"
1132 1267  
1133 1268          # remove the logfile, before creating it to survive potential noclobber settings
1134 1269  
1135 1270          ${RM} ${LOGFILE} 2>/dev/null
     1271 +        
     1272 +        do_start=0
1136 1273  
1137      -        #
1138      -        # Start PostgreSql, the postmaster searches for databases in the directory of the PGDATA variable,
1139      -        # and it will listen on the port of the PGORT varaible. The logfile will be stored in the file name
1140      -        # contained in the PGLOGFILE variable.
1141      -        # The postmaster is started via the pg_ctl utility.
1142      -        #
     1274 +        # start an ssh-agent and store the decrypted private key if SSH_PASSDIR is configured
1143 1275  
1144      -        if [ -z "${SMF_FMRI}" ]
     1276 +        
     1277 +        if [ -n "${SSH_PASSDIR}" ]
1145 1278          then
1146      -                ${SU} - ${USER} -c " ${ENVSC} ${TASK_COMMAND} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl start -l ${PGLOGFILE} ${OUTPUT}" > /dev/null
1147      -                rc_start_command=$?
1148      -        else
     1279 +        
     1280 +                ${CP} -p ${SSH_PASSDIR}/${RESOURCE}-phrase /tmp/${RESOURCE}-phrase
1149 1281  
1150      -                # start under the right user in an smf manifest you source a ksh script, regardless of the users login shell
     1282 +                if [ -z "${SMF_FMRI}" ]
     1283 +                then
     1284 +                        ${CHOWN} ${USER} /tmp/${RESOURCE}-phrase
     1285 +                        ${SU} ${USER} -c " ${TASK_COMMAND} ${MYDIR}/${MYNAME} -R ${RESOURCE} -G ${RESOURCEGROUP} -P ${PARFILE} start_ssh_agent "> /dev/null 2>&1
     1286 +                        if [ ${?} -ne 0 ]
     1287 +                        then
     1288 +                                do_start=1
     1289 +                        fi
     1290 +                else
     1291 +                        ${MYDIR}/${MYNAME} -R ${RESOURCE} -G ${RESOURCEGROUP} -P ${PARFILE} start_ssh_agent > /dev/null 2>&1
     1292 +                        if [ ${?} -ne 0 ]
     1293 +                        then
     1294 +                                do_start=1
     1295 +                        fi
     1296 +                fi
1151 1297  
1152      -                if [ -n "${ENVSCRIPT}" ]
     1298 +                ${RM} /tmp/${RESOURCE}-phrase
     1299 +
     1300 +
     1301 +                # store the SSH_AUTH_SOCK value in the SOCK variable
     1302 +
     1303 +                SOCK=
     1304 +                if [ ${do_start} -eq 0 ]
1153 1305                  then
1154      -                        . ${ENVSCRIPT}
     1306 +                        SOCK=`${GREP} SSH_AUTH_SOCK /tmp/${RESOURCE}-ssh`
     1307 +                        SOCK="${ENV} ${SOCK}"
1155 1308                  fi
     1309 +        fi
1156 1310  
1157      -                ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl start -l ${PGLOGFILE} >${LOGFILE} 2>&1
1158      -                rc_start_command=$?
     1311 +        # If a standby host is configured, check if the standby host is available and configured/acting
     1312 +        # as a standby. If everything is ok continue with the startup. If not, do not start the PostgreSQL
     1313 +        # resource.
     1314 +
     1315 +        if [ -n "${STDBY_HOST}" ] && [ ${do_start} -eq 0 ]
     1316 +        then
     1317 +
     1318 +                if ${PING} ${STDBY_HOST} ${STDBY_PING} >/dev/null 2>&1
     1319 +                then
     1320 +                        debug_message "Function: start_pgs - the host  ${STDBY_HOST} is accessible"
     1321 +                
     1322 +                        # As the PostgreSQL user perform a check on the standby host, to determine if it
     1323 +                        # is configured as a primary, it runs as a primary, or it runs as a standby database.
     1324 +        
     1325 +                        if [ -z "${SMF_FMRI}" ]
     1326 +                        then
     1327 +        
     1328 +                                ${SU} ${USER} -c " ${TASK_COMMAND} ${SOCK} ${SSH} ${STDBY_USER}@${STDBY_HOST} ${MYDIR}/${MYNAME} -R ${STDBY_RS} -G ${STDBY_RG} -P ${STDBY_PARFILE} check_stdby "> /dev/null 2>&1
     1329 +                                if [ ${?} -ne 0 ]
     1330 +                                then
     1331 +                                        do_start=1
     1332 +                                fi
     1333 +                        else
     1334 +                                ${SOCK} ${SSH} ${STDBY_USER}@${STDBY_HOST} ${MYDIR}/${MYNAME} -R ${STDBY_RS} -G ${STDBY_RG} -P ${STDBY_PARFILE} check_stdby ${OUTPUT} >/dev/null 2>&1
     1335 +                                if [ ${?} -ne 0 ]
     1336 +                                then
     1337 +                                        do_start=1
     1338 +                                fi
     1339 +        
     1340 +                        fi
     1341 +                        if [ $do_start -ne 0 ]
     1342 +                        then 
     1343 +                                # SCMSGS
     1344 +                                # @explanation
     1345 +                                # The PostgreSQL resource on the standby host is not 
     1346 +                                # configured as a standby or acting as a primary.
     1347 +                                # @user_action
     1348 +                                # Consult the logs on the standby host and insure, that
     1349 +                                # the standby host is configured as a standby database, 
     1350 +                                # if it is running as a primary, reconfigure and restart it.
     1351 +                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1352 +                                        "Function: start_pgs - resource %s on host %s is not configured/running as a standby database" \
     1353 +                                        "${STDBY_RS}" "${STDBY_HOST}"
     1354 +                        else
     1355 +                                debug_message "Function: start_pgs - the resource ${STDBY_RS} on host ${STDBY_HOST} is configured/running as a standby database"
     1356 +                        fi
     1357 +        
     1358 +                else
     1359 +                        # SCMSGS
     1360 +                        # @explanation
     1361 +                        # The standby host is not up and running.
     1362 +                        # @user_action
     1363 +                        # Consult the logs on the standby host and insure, that
     1364 +                        # the standby host is answering on ping requests of the primary host.
     1365 +                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1366 +                                "Function: start_pgs - the standby host %s is not answering on ping" \
     1367 +                                "${STDBY_HOST}"
     1368 +                        do_start=1
     1369 +                fi
1159 1370          fi
1160 1371  
     1372 +        # continue on the start process
     1373 +
     1374 +        if [ ${do_start} -eq 0 ] 
     1375 +        then
     1376 +                
     1377 +                # Start PostgreSql, the postmaster searches for databases in the directory of the PGDATA variable,
     1378 +                # and it will listen on the port of the PGORT varaible. The logfile will be stored in the file name
     1379 +                # contained in the PGLOGFILE variable.
     1380 +                # The postmaster is started via the pg_ctl utility.
     1381 +                #
     1382 +        
     1383 +                if [ -z "${SMF_FMRI}" ]
     1384 +                then
     1385 +                        ${SU} ${USER} -c " ${ENVSC} ${TASK_COMMAND} ${SOCK} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl start -l ${PGLOGFILE} ${OUTPUT}" > /dev/null
     1386 +                        rc_start_command=$?
     1387 +                else
     1388 +        
     1389 +                        # start under the right user in an smf manifest you source a ksh script, regardless of the users login shell
     1390 +        
     1391 +                        if [ -n "${ENVSCRIPT}" ]
     1392 +                        then
     1393 +                                . ${ENVSCRIPT}
     1394 +                        fi
     1395 +        
     1396 +                        ${SOCK} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl start -l ${PGLOGFILE} >${LOGFILE} 2>&1
     1397 +                        rc_start_command=$?
     1398 +                fi
     1399 +                
     1400 +                # if an ssh-agent was started, remember the postmaster pid in /tmp/${RESOURCE}-pid
     1401 +
     1402 +                if [ -n "${SOCK}" ] && [ ${rc_start_command} -eq 0 ]
     1403 +                then
     1404 +                        START_TIMEOUT=`${SCHA_RESOURCE_GET} -O START_TIMEOUT -R ${RESOURCE} -G ${RESOURCEGROUP}`
     1405 +                        MAX_START=`expr ${START_TIMEOUT} \* 70 \/ 100`
     1406 +                        
     1407 +                        # give PostgreSQL a chance to construct the ${PGDATA}/postmaster pid, it is 
     1408 +                        # done asynchronously
     1409 +
     1410 +                        PID_LINES=0
     1411 +                        while [ ${SECONDS} -lt ${MAX_START} ] && [ ${PID_LINES} -eq 0 ]
     1412 +                        do
     1413 +                                if [ -f ${PGDATA}/postmaster.pid ]
     1414 +                                then
     1415 +                                        PID_LINES=`${WC} -l ${PGDATA}/postmaster.pid|${AWK} '{print $1}'`
     1416 +                                fi
     1417 +                                ${SLEEP} 2
     1418 +                        done
     1419 +
     1420 +                        ${RM} /tmp/${RESOURCE}-pid 2>/dev/null
     1421 +                        ${HEAD} -1 ${PGDATA}/postmaster.pid >/tmp/${RESOURCE}-pid
     1422 +                fi
     1423 +        else
     1424 +                rc_start_command=1
     1425 +
     1426 +                # disable the pmf tag and run a sleep in the background, to assure, that there will be a valid pmftag during the start phase
     1427 +
     1428 +                START_TIMEOUT=`${SCHA_RESOURCE_GET} -O START_TIMEOUT -R ${RESOURCE} -G ${RESOURCEGROUP}`
     1429 +                sleep ${START_TIMEOUT} &
     1430 +                ${PMFADM} -s ${RESOURCEGROUP},${RESOURCE},0.svc
     1431 +
     1432 +                # As a workaround until RFE 6629606 is implemented, kill the gds_svc start method
     1433 +                # to speed up the transition into START_FAILED.
     1434 +                # If gds_svc_start gets killed the resource transition into START_FAILED and does not
     1435 +                # wait until the start_timeout expires.
     1436 +
     1437 +                ${PKILL} -u root -f "gds_svc_start .*-R ${RESOURCE} " >/dev/null
     1438 +        fi
     1439 +
1161 1440          debug_message "Function: start_pgs - End"
1162 1441          return ${rc_start_command}
1163 1442  }
1164 1443  
1165 1444  stop_pgs()
1166 1445  {
1167 1446          #
1168 1447          # Stop PostgreSQL
1169 1448          #
1170 1449  
↓ open down ↓ 37 lines elided ↑ open up ↑
1208 1487          # The PostgreSQL database server is shut down with the specified
1209 1488          # option.
1210 1489          # @user_action
1211 1490          # None
1212 1491          scds_syslog -p daemon.notice -t $(syslog_tag) -m \
1213 1492               "stop_pgs: Stop PostgreSQL with the option %s " \
1214 1493               "fast"
1215 1494          
1216 1495          if [ -z "${SMF_FMRI}" ]
1217 1496          then
1218      -                ${SU} - ${USER} -c " ${ENVSC} ${TASK_COMMAND} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m fast ${OUTPUT}" > /dev/null
     1497 +                ${SU} ${USER} -c " ${ENVSC} ${TASK_COMMAND} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m fast ${OUTPUT}" > /dev/null
1219 1498                  rc_stop_command=$?
1220 1499          else
1221 1500  
1222 1501                  # stop under the right user in a smf manifest
1223 1502  
1224 1503                  if [ -n "${ENVSCRIPT}" ]
1225 1504                  then
1226 1505                          . ${ENVSCRIPT}
1227 1506                  fi
1228 1507  
1229 1508                  ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m fast >${LOGFILE} 2>&1
1230 1509                  rc_stop_command=$?
1231 1510          fi
1232 1511  
1233 1512          # Determine if postgres is really stopped, if not perform an immediate shutdown.
1234 1513          # The server is specified by the triple user, PGPORT and the PGDATA variable.
1235      -        # The immediate shutdown stop the server processes without disconnecting the clients.
     1514 +        # The immediate shutdown stops the server processes without disconnecting the clients.
     1515 +        # The immediate shutdown will be performd only, if the postgres database is not configured as
     1516 +        # a standby database, because then an immediate shutdown will not succeed in a standby configuration.
1236 1517          
1237      -        if ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null
     1518 +        
     1519 +        if [ ! -f ${PGDATA}/recovery.conf ]
1238 1520          then
     1521 +                if ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null
     1522 +                then
     1523 +                        
     1524 +                        scds_syslog -p daemon.notice -t $(syslog_tag) -m \
     1525 +                             "stop_pgs: Stop PostgreSQL with the option %s " \
     1526 +                             "immediate"
     1527 +                        
     1528 +                        if [ -z "${SMF_FMRI}" ]
     1529 +                        then
     1530 +                                ${SU} ${USER} -c "${ENVSC} ${TASK_COMMAND} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m immediate ${OUTPUT_APP}" > /dev/null
     1531 +                                rc_stop_command=$?
     1532 +                        else
1239 1533                  
1240      -                scds_syslog -p daemon.notice -t $(syslog_tag) -m \
1241      -                     "stop_pgs: Stop PostgreSQL with the option %s " \
1242      -                     "immediate"
     1534 +                                # stop under the right user in a smf manifest
1243 1535                  
1244      -                if [ -z "${SMF_FMRI}" ]
1245      -                then
1246      -                        ${SU} - ${USER} -c "${ENVSC} ${TASK_COMMAND} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m immediate ${OUTPUT_APP}" > /dev/null
1247      -                        rc_stop_command=$?
1248      -                else
     1536 +                                if [ -n "${ENVSCRIPT}" ]
     1537 +                                then
     1538 +                                        . ${ENVSCRIPT}
     1539 +                                fi
1249 1540          
1250      -                        # stop under the right user in a smf manifest
1251      -        
1252      -                        if [ -n "${ENVSCRIPT}" ]
1253      -                        then
1254      -                                . ${ENVSCRIPT}
     1541 +                                ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m immediate >>${LOGFILE} 2>&1
     1542 +                                rc_stop_command=$?
1255 1543                          fi
1256      -
1257      -                        ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m immediate >>${LOGFILE} 2>&1
1258      -                        rc_stop_command=$?
1259 1544                  fi
     1545 +        else
     1546 +                debug_message "Function: stop_pgs - It is a standby database, do not stop with immediate"
1260 1547          fi
1261 1548  
1262 1549          # determine if postgres is really stopped, if not kill the parent of the postmaster with -9
1263 1550          
1264 1551          if ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null
1265 1552          then
1266 1553                  # SCMSGS
1267 1554                  # @explanation
1268 1555                  # The previous stop attempts for PostgreSQL failed. The server
1269 1556                  # is now killed with kill -9.
1270 1557                  # @user_action
1271 1558                  # None
1272 1559                  scds_syslog -p daemon.notice -t $(syslog_tag) -m \
1273 1560                       "stop_pgs: Stop PostgreSQL process %s with kill -9 " \
1274 1561                       "${pgrspid}"
1275 1562  
1276 1563                  ${KILL} -9 ${pgrspid}
1277 1564                  rc_stop_command=$?
1278 1565          fi
1279 1566  
     1567 +        if [ -n "${SSH_PASSDIR}" ]
     1568 +        then
     1569 +                # stop the ssh-agent
     1570 +
     1571 +                SSH_PID=
     1572 +                if  [ -f /tmp/${RESOURCE}-ssh ]
     1573 +                then
     1574 +                        debug_message "Function: stop_pgs - stop the ssh agent"
     1575 +
     1576 +                        # source /tmp/${RESOURCE}-ssh to get the variable SSH_AGENT_PID
     1577 +
     1578 +                        . /tmp/${RESOURCE}-ssh
     1579 +                        
     1580 +                        SSH_PID="${ENV} SSH_AGENT_PID=${SSH_AGENT_PID}"
     1581 +        
     1582 +                        if [ -z "${SMF_FMRI}" ]
     1583 +                        then
     1584 +                                ${SU} ${USER} -c "${TASK_COMMAND} ${SSH_PID} ${SSH_AGENT} -k ${OUTPUT_APP}"
     1585 +                                rc_stop_command=$?
     1586 +                        else
     1587 +                                ${SSH_PID} ${SSH_AGENT} -k >>${LOGFILE}
     1588 +                                rc_stop_command=$?
     1589 +                        fi
     1590 +
     1591 +                        # if the ssh-agent process is still there, kill it with -9
     1592 +
     1593 +                        if ${PS} -p ${SSH_AGENT_PID} >/dev/null 2>&1
     1594 +                        then
     1595 +                                debug_message "Function: stop_pgs - The ssh-agent ${SSH_AGENT_PID} survived his stop request, kill it with -9"
     1596 +                                ${KILL} -9 ${SSH_AGENT_PID}
     1597 +                        fi
     1598 +                else
     1599 +                        # SCMSGS
     1600 +                        # @explanation
     1601 +                        # It can not be determined which ssh agent is working for the user/database,
     1602 +                        # it is now killed by PMF using the configured stop signal.
     1603 +                        # @user_action
     1604 +                        # None
     1605 +                        scds_syslog -p daemon.notice -t $(syslog_tag) -m \
     1606 +                             "stop_pgs: Allow pmf to stop the remaining ssh-agent for the user %s" \
     1607 +                             "${USER}"
     1608 +                fi
     1609 +
     1610 +        fi
     1611 +
1280 1612          debug_message "Function: stop_pgs - End"
1281 1613          return ${rc_stop_command}
1282 1614  }
1283 1615  
1284 1616  check_pgs()
1285 1617  {
1286 1618          # 
1287 1619          # Probe PostgreSQL
1288 1620          #
1289 1621  
↓ open down ↓ 5 lines elided ↑ open up ↑
1295 1627          # construct the necessary redirection and source variables
1296 1628  
1297 1629          set_shell_specifics
1298 1630  
1299 1631          # Define the appropriate newtask command.
1300 1632          # The Project will be derived according to the call method,
1301 1633          # either from the smf service or from the cluster resource / resource group
1302 1634  
1303 1635          srm_function ${USER}
1304 1636  
     1637 +        # determine the parent postmaster pid
     1638 +
     1639 +        pgrspid=""
     1640 +        if [ -f ${PGDATA}/postmaster.pid ]
     1641 +        then
     1642 +                pgrspid=`${HEAD} -1 ${PGDATA}/postmaster.pid`
     1643 +        else
     1644 +
     1645 +                # the pid store is created only if a ssh passphrase is defined
     1646 +                # in this case get the pid from /tmp/${RESOURCE}-pid
     1647 +
     1648 +                if [ -n "${SSH_PASSDIR}" ]
     1649 +                then
     1650 +                        pgrspid=`${CAT} /tmp/${RESOURCE}-pid`
     1651 +                fi
     1652 +        fi
     1653 +
1305 1654          # Determine if the gds start process is already completed, or the database start is far enough to allow connections
1306 1655          # The criteria is the existence of the postmaster.pid file in the PGDATA directory.
1307 1656          # As long as the GDS start is not complete, probe error messages will be suppressed.
1308 1657  
1309 1658          wait_for_online=0
1310 1659          
1311 1660          ${PGREP} -u root -f "gds_svc_start .*-R ${RESOURCE} " >/dev/null
1312 1661          if [ ${?} -eq 0 ]
1313 1662          then
1314 1663                  debug_message "Function: check_pgs - wait for online detected" 
1315 1664                  wait_for_online=1
1316      -                if [ -f ${PGDATA}/postmaster.pid ]
     1665 +                if [ -n "${pgrspid}" ]
1317 1666                  then
1318      -                        pgrspid=`${HEAD} -1 ${PGDATA}/postmaster.pid`
1319 1667                          if ! ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null
1320 1668                          then
1321 1669                                  debug_message "Function: check_pgs - wait for online detected, postmaster is not running" 
1322 1670                                  rc_check_command=100
1323 1671                          else
1324 1672                                  debug_message "Function: check_pgs - wait for online detected, postmaster is running proceed with normal checks" 
1325 1673                          fi
1326 1674                  else
1327 1675                          debug_message "Function: check_pgs - wait for online detected, postmaster pid file ${PGDATA}/postmaster.pid not found" 
1328 1676                          rc_check_command=100
1329 1677                  fi
1330 1678          fi
1331 1679  
1332      -        if [ ${rc_check_command} -ne 0 ]
     1680 +        # If a passphrase is defined a ssh agent is running together with the PostgreSQL deamon
     1681 +        # each of the daemons satisfies pmf/smf, so we have to check manually for the processes to run.
     1682 +        # If either the ssh-agent or the PostgreSQL daemons are not running, exit with 100.
     1683 +        # This has to be done, because pmf/smf will not trigger a restart if only one of the process trees are gone.
     1684 +
     1685 +        if [ -n "${SSH_PASSDIR}" ] && [ -n "${pgrspid}" ]
1333 1686          then
     1687 +                
     1688 +                if ! ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null
     1689 +                then
     1690 +                        # SCMSGS
     1691 +                        # @explanation
     1692 +                        # The PostgreSQL process is not running.
     1693 +                        # @user_action
     1694 +                        # None
     1695 +                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1696 +                                "check_pgs: The PostgreSQL process %s is not running" \
     1697 +                                "${pgrspid}"
     1698 +                        rc_check_command=100
     1699 +                        return ${rc_check_command}
     1700 +                                
     1701 +                fi
     1702 +                
     1703 +                # Determine if the necessary ssh-agent is running. If PostgreSQL is running 
     1704 +                # without the ssh-agent, the replication is not working, so we have to return 100
     1705 +
     1706 +                if [ -f /tmp/${RESOURCE}-ssh ]
     1707 +                then
     1708 +
     1709 +                        sshpid=`${GREP} SSH_AGENT_PID /tmp/${RESOURCE}-ssh|${AWK} -F= '{print $2}'`
     1710 +                        if ! ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${sshpid}>/dev/null
     1711 +                        then
     1712 +                                # SCMSGS
     1713 +                                # @explanation
     1714 +                                # The ssh-agent process associated with the PostgreSQL database 
     1715 +                                # is not running.
     1716 +                                # @user_action
     1717 +                                # None
     1718 +                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1719 +                                        "check_pgs: The ssh-agent process %s is not running" \
     1720 +                                        "${sshpid}"
     1721 +                                rc_check_command=100
     1722 +                                return ${rc_check_command}
     1723 +                        fi
     1724 +
     1725 +                else
     1726 +
     1727 +                        # SCMSGS
     1728 +                        # @explanation
     1729 +                        # The file /tmp/<resourcename>-ssh containing the necessary information to manage 
     1730 +                        # the ssh-agent together with the PostgreSQL database is unavailable.
     1731 +                        # @user_action
     1732 +                        # None
     1733 +                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1734 +                                "check_pgs: The ssh-agent information file %s is unavailable" \
     1735 +                                "/tmp/${RESOURCE}-ssh"
     1736 +                        rc_check_command=100
     1737 +                        return ${rc_check_command}
     1738 +
     1739 +                fi
     1740 +        
     1741 +        fi
     1742 +
     1743 +        # If there is no postmaster.pid during wait for online, or the database will not
     1744 +        # accept updates, because it is configured as a standby database, terminate the probe.
     1745 +        # To trigger an early exit of the probe, it is enough, that a recover.conf exists in $PGDATA.
     1746 +        # So effectively the agent relies on process monitoring if a database is configured as a standby database.
     1747 +
     1748 +
     1749 +        if [ ${rc_check_command} -ne 0 ] || [ -f ${PGDATA}/recovery.conf ]
     1750 +        then
1334 1751                  debug_message "Function: check_pgs - End"
1335 1752                  return ${rc_check_command}
1336 1753          fi
1337 1754  
1338 1755          # construct the necessary environment variables
1339 1756  
1340 1757          LIBPATH=
1341 1758          if [ -n "${LD_LIBRARY_PATH}" ]
1342 1759          then
1343 1760                  LIBPATH="${ENV} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
↓ open down ↓ 25 lines elided ↑ open up ↑
1369 1786  
1370 1787          DBCAT="select datname from pg_database"
1371 1788          DBTRUNC="truncate ${SCTABLE}"
1372 1789          DBINS="insert into ${SCTABLE} (sccol) values('hello im there')"
1373 1790          DBSEL="select * from ${SCTABLE}"
1374 1791  
1375 1792          # check if the catalog of the postgres database is accessible
1376 1793  
1377 1794          debug_message "Function: check_pgs - check if the database catalog is accessible with ${SCDB} "
1378 1795  
1379      -        ${SU} - ${USER} -c "${OPEN_BRACKET} ${TASK_COMMAND} ${LIBPATH} $HOST ${PASSWORD} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/psql -d ${SCDB} -U ${SCUSER} -c \"${DBCAT}\" ${CAT_OUTPUT} ${CLOSE_BRACKET} ${CAT_ERRPUT} " >/dev/null
     1796 +        ${SU} ${USER} -c "${OPEN_BRACKET} ${TASK_COMMAND} ${LIBPATH} $HOST ${PASSWORD} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/psql -d ${SCDB} -U ${SCUSER} -c \"${DBCAT}\" ${CAT_OUTPUT} ${CLOSE_BRACKET} ${CAT_ERRPUT} " >/dev/null
1380 1797          rc_check_command=$?
1381 1798  
1382 1799          # Return ${NOCONRET} if the connect fails, otherwise proceed with the check
1383 1800  
1384 1801          if [ ${rc_check_command} -ne 0 ]
1385 1802          then
1386 1803  
1387 1804                  debug_message "Function: check_pgs - connect to database ${SCDB} failed"
1388 1805  
1389 1806                  if [ ${wait_for_online} -eq 0 ]
↓ open down ↓ 36 lines elided ↑ open up ↑
1426 1843          fi
1427 1844  
1428 1845          # manipulate the table SCTABLE and exit 100 if the inserted string is not there, exit 10 if the connection to
1429 1846          # the database fails
1430 1847  
1431 1848          if [ ${rc_check_command} -eq 0 ]
1432 1849          then
1433 1850  
1434 1851                  debug_message "Function: check_pgs - manipulate the table ${SCTABLE}"
1435 1852  
1436      -                ${SU} - ${USER} -c "${OPEN_BRACKET} ${TASK_COMMAND} ${LIBPATH} $HOST ${PASSWORD} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/psql -d ${SCDB} -U ${SCUSER} -c \"${DBTRUNC};${DBINS};${DBSEL}\" ${TBL_OUTPUT} ${CLOSE_BRACKET} ${TBL_ERRPUT} " >/dev/null
     1853 +                ${SU} ${USER} -c "${OPEN_BRACKET} ${TASK_COMMAND} ${LIBPATH} $HOST ${PASSWORD} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/psql -d ${SCDB} -U ${SCUSER} -c \"${DBTRUNC};${DBINS};${DBSEL}\" ${TBL_OUTPUT} ${CLOSE_BRACKET} ${TBL_ERRPUT} " >/dev/null
1437 1854                  rc_check_command=$?
1438 1855  
1439 1856                  # Return ${NOCONRET} if the connect fails, otherwise proceed with the check
1440 1857  
1441 1858                  if [ ${rc_check_command} -ne 0 ]
1442 1859                  then
1443 1860  
1444 1861                          debug_message "Function: check_pgs - connect to database ${SCDB} failed"
1445 1862  
1446 1863                          if [ ${wait_for_online} -eq 0 ]
↓ open down ↓ 15 lines elided ↑ open up ↑
1462 1879                                  if [ ${wait_for_online} -eq 0 ]
1463 1880                                  then
1464 1881                                          # SCMSGS
1465 1882                                          # @explanation
1466 1883                                          # The monitoring action on the
1467 1884                                          # specified table failed.
1468 1885                                          # @user_action
1469 1886                                          # None
1470 1887                                          scds_syslog -p daemon.err -t $(syslog_tag) -m \
1471 1888                                                  "check_pgs: The test database manipulation failed for database %s, user %s and table %s" \
1472      -                                                "${SCDB}" "${SCUSER}" "$SCTABLE}"
     1889 +                                                "${SCDB}" "${SCUSER}" "${SCTABLE}"
1473 1890                                  fi
1474 1891  
1475 1892                                  rc_check_command=100
1476 1893                                  debug_message "Function: check_pgs - manipulation of the table ${SCTABLE} failed"
1477 1894  
1478 1895                          else
1479 1896  
1480 1897                                  debug_message "Function: check_pgs - manipulation of the table ${SCTABLE} successful"
1481 1898  
1482 1899                          fi
1483 1900                  fi
1484 1901          fi      
1485 1902  
1486 1903          debug_message "Function: check_pgs - End"
1487 1904          return ${rc_check_command}
     1905 +}
     1906 +
     1907 +check_stdby()
     1908 +{
     1909 +        # 
     1910 +        # Check if the current postgres database is configured or running as a standby database.
     1911 +        # This function is called from the start command of the remote host.
     1912 +        # The error messages are processed by scds_syslog, and they are transported via
     1913 +        # standard out to the remote host.
     1914 +        #
     1915 +        # This function will generate up to two error messages in the postgres logfile.
     1916 +
     1917 +        debug_message "Function: check_stdby - Begin"
     1918 +        ${SET_DEBUG}
     1919 +
     1920 +        rc_check_stdby_command=0
     1921 +        if [ -f ${PGDATA}/recovery.conf ]
     1922 +        then
     1923 +
     1924 +                # We are running as the PostgreSQL user, so exporting the environment is sufficient.
     1925 +
     1926 +                export PGPORT
     1927 +
     1928 +                # The variable PASSWORD is set to the database user login password.
     1929 +
     1930 +                if [ -n "${SCPASS}" ]
     1931 +                then
     1932 +                        export PGPASSWORD=${SCPASS}
     1933 +                fi
     1934 +
     1935 +                if [ -n "${PGHOST}" ]
     1936 +                then
     1937 +                        export PGHOST
     1938 +                fi
     1939 +                export PGPORT
     1940 +                export LD_LIBRARY_PATH
     1941 +                
     1942 +                # check the database if it accepts inserts
     1943 +
     1944 +                ${PGROOT}/bin/psql -d ${SCDB} -U ${SCUSER} -c "insert into ${SCTABLE} (sccol) values('standby test');" >/dev/null 2>&1
     1945 +                if [ ${?} -eq 0 ]
     1946 +                then
     1947 +                        # SCMSGS
     1948 +                        # @explanation
     1949 +                        # The database is running as a primary database, but is configured to be a standby.
     1950 +                        # @user_action
     1951 +                        # If you want to start the old primary database, reload the primary and restart 
     1952 +                        # the standby database.
     1953 +                        scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1954 +                                "check_stdby: The database in %s is not running as a standby database, reload the primary and restart the standby database." \
     1955 +                                "${PGDATA}" 
     1956 +                        rc_check_stdby_command=1
     1957 +
     1958 +                else
     1959 +
     1960 +                        # Check if the rolchanger is currently doing his work.
     1961 +
     1962 +                        if [ -f /tmp/${ROLECHG_RS}_rolechg.lck ]
     1963 +                        then
     1964 +
     1965 +                                # SCMSGS
     1966 +                                # @explanation
     1967 +                                # The database is running as a standby database, but is currently reconfigured to run as a primary.
     1968 +                                # @user_action
     1969 +                                # If you want to start the old primary database, reload the primary and restart 
     1970 +                                # the standby database.
     1971 +                                scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1972 +                                        "check_stdby: The database in %s is reconfigured to run as a primary database, reload the primary and restart the standby database." \
     1973 +                                        "${PGDATA}" 
     1974 +                                rc_check_stdby_command=1
     1975 +                        else
     1976 +                                debug_message "Function: check_stdby - the database in ${PGDATA} is configured or running as a standby database"
     1977 +                        fi
     1978 +
     1979 +                fi
     1980 +                
     1981 +        else
     1982 +
     1983 +                # SCMSGS
     1984 +                # @explanation
     1985 +                # The database is not configured as a standby database.
     1986 +                # @user_action
     1987 +                # Create an appropriate recovery.conf command, reload the primary 
     1988 +                # and restart the standby database.
     1989 +                scds_syslog -p daemon.err -t $(syslog_tag) -m \
     1990 +                        "check_stdby: The database in %s is not configured as a standby database, create the recovery.conf command" \
     1991 +                        "${PGDATA}" 
     1992 +                rc_check_stdby_command=1
     1993 +
     1994 +        fi
     1995 +
     1996 +        debug_message "Function: check_stdby - End"
     1997 +        return ${rc_check_stdby_command}
1488 1998  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX