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
1 1 #
2 2 # CDDL HEADER START
3 3 #
4 4 # The contents of this file are subject to the terms of the
5 5 # Common Development and Distribution License (the License).
6 6 # You may not use this file except in compliance with the License.
7 7 #
8 8 # You can obtain a copy of the license at usr/src/CDDL.txt
9 9 # or http://www.opensolaris.org/os/licensing.
10 10 # See the License for the specific language governing permissions
11 11 # and limitations under the License.
12 12 #
|
↓ 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
38 38 GETENT=/usr/bin/getent
39 39 AWK=/usr/bin/awk
40 40 NAWK=/usr/bin/nawk
41 41 CAT=/usr/bin/cat
42 42 EGREP=/usr/bin/egrep
43 43 GREP=/usr/bin/grep
44 44 ENV=/usr/bin/env
45 45 HEAD=/usr/bin/head
46 46 PS=/usr/bin/ps
47 47 PGREP=/usr/bin/pgrep
48 48 KILL=/usr/bin/kill
49 49 IPCS=/usr/bin/ipcs
|
↓ 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
70 78
71 79 RESOURCE=`/usr/bin/svcprop -p parameters/Resource ${SMF_FMRI}`
72 80
73 81 # Resource Group
74 82
75 83 RESOURCEGROUP=`/usr/bin/svcprop -p parameters/Resource_group ${SMF_FMRI}`
76 84
77 85 # Start Project
78 86
79 87 Project=:default
80 88 if /usr/bin/svcprop ${SMF_FMRI}|grep start/project >/dev/null
81 89 then
82 90 Project=`/usr/bin/svcprop -p start/project ${SMF_FMRI}`
83 91 if [ "${Project}" != ":default" ]
84 92 then
85 93 PROJ_OPT=" -P ${Project}"
86 94 ZONE_PROJECT=${Project}
87 95 fi
88 96 fi
89 97
90 98 # Parameter file
91 99
92 100 PARFILE=`/usr/bin/svcprop -p parameters/Parameter_File ${SMF_FMRI}`
93 101
94 102 debug_message "Function: get_fmri_parameters - End "
95 103 }
96 104
97 105 set_shell_specifics()
98 106 {
99 107
100 108 # Set variables to construct sourcing and output redirection depending
101 109 # on the login shell of the user
102 110
103 111 debug_message "Function: set_shell_specifics - Begin"
104 112 ${SET_DEBUG}
105 113
106 114 ENVSC=
107 115
108 116 if /usr/bin/getent passwd ${USER} | /usr/bin/awk -F: '{print $7}' | /usr/bin/grep csh > /dev/null
109 117 then
110 118
111 119 # C shell specifics
112 120
113 121 # sourcing
114 122
115 123 if [ -n "${ENVSCRIPT}" ]
116 124 then
117 125 ENVSC="source ${ENVSCRIPT};"
118 126 fi
119 127
120 128 # brackets for subshells
121 129
122 130 OPEN_BRACKET="("
123 131 CLOSE_BRACKET=")"
124 132
125 133 # redirection
126 134
127 135 OUTPUT_APP=">>& ${LOGFILE}"
128 136 OUTPUT=">& ${LOGFILE}"
129 137 CAT_OUTPUT="> /tmp/${RESOURCE}-${USER}-cat-out"
130 138 CAT_ERRPUT=">& /tmp/${RESOURCE}-${USER}-cat-err"
131 139 TBL_OUTPUT="> /tmp/${RESOURCE}-${USER}-tbl-out"
132 140 TBL_ERRPUT=">& /tmp/${RESOURCE}-${USER}-tbl-err"
133 141 else
134 142
135 143 # Korn shell specifics
136 144
137 145 # sourcing
138 146
139 147 if [ -n "${ENVSCRIPT}" ]
140 148 then
141 149 ENVSC=". ${ENVSCRIPT};"
142 150 fi
143 151
144 152 # no subshell needed in a ksh
145 153
146 154 OPEN_BRACKET=
147 155 CLOSE_BRACKET=
148 156
149 157 # redirection
150 158
151 159 OUTPUT_APP=">> ${LOGFILE} 2>&1"
152 160 OUTPUT="> ${LOGFILE} 2>&1"
153 161 CAT_OUTPUT="> /tmp/${RESOURCE}-${USER}-cat-out"
154 162 CAT_ERRPUT="2> /tmp/${RESOURCE}-${USER}-cat-err"
155 163 TBL_OUTPUT="> /tmp/${RESOURCE}-${USER}-tbl-out"
156 164 TBL_ERRPUT="2> /tmp/${RESOURCE}-${USER}-tbl-err"
157 165 fi
158 166
159 167
160 168 debug_message "Function: set_shell_specifics - End"
161 169 }
162 170
163 171 create_pfile()
164 172 {
165 173
166 174 # Creation of the parameter file. This function is used at registration
167 175 # time only.
168 176
169 177 debug_message "Function: create_pfile - Begin "
170 178 ${SET_DEBUG}
171 179
172 180 if [ -z "${PFILE}" ]
173 181 then
174 182 ${ECHO} "ERROR: set the variable parameter file"
175 183 return 1
176 184 fi
177 185
178 186 # determine wether the parameter file needs to be created in a zone or not
179 187
180 188 zonecmd=
181 189
182 190 pfile_tmp="/tmp/pgspfile.${RS}"
183 191
184 192 # get the zonename of the resource group
185 193
186 194 target_zone=$(rgs_zonename)
187 195 if [ -n "${target_zone}" ]
188 196 then
189 197 zonecmd="${ZLOGIN} ${target_zone}"
190 198 fi
191 199
192 200 # check the directory of the parameter file
193 201
194 202 pdir=`${zonecmd} ${DIRNAME} ${PFILE}`
195 203
196 204 # test for the existance of the parameter files directory either in the local or
197 205 # the global zone according to the zone entry in the nodelist
198 206
199 207 if ! ${zonecmd} ${TEST} -d ${pdir}
200 208 then
201 209 ${ECHO} "ERROR: set the variable parameter file in an existing directory"
202 210 return 1
203 211 fi
204 212
205 213 # create the parameter file
206 214
207 215 ${ECHO} "Prepare the parameter file ${PFILE}"
208 216
209 217 ${CAT} <<EOF > ${pfile_tmp}
210 218
211 219 #
212 220 # Content for the parameter file
213 221 #
214 222 # USER - The Solaris user, which owns the PostgreSQL database
215 223 # PGROOT - Contains the path to the PostgreSQL directory. Below this
216 224 # directory the postgres binaries are located in the ./bin
217 225 # directory.
218 226 # PGDATA - Contains the path to the databases of this specific PostgreSQL
219 227 # instance. The pg_hba.conf needs to be here.
220 228 # PGPORT - Port where the postmaster process will be listening to.
221 229 # PGHOST - Hostname where the postmaster process is listening to, or a directory where the
222 230 # Unix socket file is stored.
223 231 # If set to a valid hostname, the PGHOST variable forces the probe to
224 232 # traverse the TCP/IP stack. If the PGHOST variable is empty or starts with a "/",
225 233 # the probe will use a socket. If the PGHOST variable starts with a "/", the entry must
226 234 # be the directory which contains the socket file.
227 235 # PGLOGFILE - Logfile where the log messages of the postmaster will be stored.
228 236 # LD_LIBRARY_PATH - This path contains all the necessary libraries for this PostgreSQL
229 237 # installation.
230 238 # Optional
231 239 # ENVSCRIPT - Script to contain PostgreSQL specific runtime variables.
232 240 # Optional
233 241 # SCDB - This specific PostgreSQL database will be monitored.
234 242 # SCUSER - PostgresSQL user to connect to the $SCDB database.
235 243 # SCTABLE - Table name in the $SCDB database. This table name will be manipulated
236 244 # to check if PostgreSQL is alive. This table will be generated at database
237 245 # preparation time.
238 246 # SCPASS - Password of the SCUSER. If no password is provided the authentication method
239 247 # for the SCDB database needs to be trusted for requests from the localhost.
240 248 # Optional
241 249 # NOCONRET - Return code for connection errors. This return code has to follow the rules
242 250 # for the generic data service. The value has to be between 1 and 100.
243 251 # 100/NOCONRET defines the number of consecutive probes to ignore for failed
244 252 # connections. A restart or failover will occur, if the number is exeeded within
245 253 # the retry interval.
246 254
247 255
248 256 USER=${USER}
249 257 PGROOT=${PGROOT}
250 258 PGDATA=${PGDATA}
251 259 PGPORT=${PGPORT}
|
↓ 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}" ]
272 317 then
273 318 ${CAT} ${pfile_tmp} | ${zonecmd} ${CAT} - \>${PFILE}
274 319 if [ $? -ne 0 ]
275 320 then
276 321 ${ECHO} "ERROR: could not create the parameter file ${PFILE}"
277 322 return 1
278 323 fi
279 324 else
280 325 ${CAT} ${pfile_tmp} > ${PFILE}
281 326 if [ $? -ne 0 ]
282 327 then
283 328 ${ECHO} "ERROR: could not create the parameter file ${PFILE}"
284 329 return 1
285 330 fi
286 331 fi
287 332
288 333 debug_message "Function: create_pfile - End "
289 334 return 0
290 335 }
291 336
292 337 validate_options()
293 338 {
294 339 debug_message "Function: validate_options - Begin"
295 340 ${SET_DEBUG}
296 341
297 342 #
298 343 # Ensure all mandatory options are set
299 344 #
300 345
301 346 for i in RESOURCE RESOURCEGROUP PARFILE
302 347 do
303 348 case ${i} in
|
↓ 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 {
342 387 #
343 388 # Validate
344 389 #
345 390
346 391 debug_message "Function: validate - Begin"
347 392 ${SET_DEBUG}
348 393
349 394 rc_validate=0
350 395
351 396 if ! val_parfile ${PARFILE} "USER PGROOT PGDATA PGPORT PGLOGFILE SCDB SCUSER SCTABLE NOCONRET"
352 397 then
353 398 debug_message "Function: validate - End"
354 399 rc_validate=1
355 400 return ${rc_validate}
356 401 fi
357 402
358 403 . ${PARFILE}
359 404
360 405 for i in `${CAT} ${PARFILE} |grep -v "^#"|grep -v "^ "|nawk -F= '{print $1}'`
361 406 do
362 407 case $i in
363 408 USER)
364 409
365 410 # Test the PostgresSQL OS user
|
↓ 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
388 433 # an existing user for the variable
389 434 # USER.
390 435 scds_syslog -p daemon.err -t $(syslog_tag) -m \
391 436 "Function: validate: User %s does not exist, an existing user is required" \
392 437 "${USER}"
393 438 rc_validate=1
394 439 else
|
↓ 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
523 568 if [ -n "${PGHOST}" ]
524 569 then
525 570
526 571 # strip of leading spaces
527 572
528 573 PGHOST=`print ${PGHOST}|${SED} 's/^ *//'`
529 574
530 575 if ${ECHO} ${PGHOST} | ${GREP} "^/" >/dev/null 2>&1
531 576 then
532 577
|
↓ 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,
574 619 # because it works in failover zones, even if there is no logical
575 620 # host configured.
576 621
577 622 # Set the laguage to C to avoid localisation problems with ifconfig
578 623
579 624 LANG=C
580 625
581 626 addr=`${GETENT} hosts ${PGHOST}| ${AWK} '{print $1}'`
582 627
583 628 # Check if the address is configured up on the node
584 629
585 630 adapter_success=1
586 631 for i in `${IFCONFIG} -a |${GREP} UP|${AWK} '{print $1}' |${EGREP} -v "zone|inet"|${GREP} ":$"|${SED} s/:$//`
587 632 do
588 633
589 634 ${IFCONFIG} ${i}|${GREP} ${addr} >/dev/null 2>&1
590 635 if [ ${?} -eq 0 ]
591 636 then
592 637 adapter_success=0
593 638 fi
594 639
595 640 done
596 641
|
↓ 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
652 697 if [ -n "${LD_LIBRARY_PATH}" ]
653 698 then
654 699 export LD_LIBRARY_PATH
655 700 if ! ${PGROOT}/bin/psql --help >/dev/null 2>&1
|
↓ 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.
678 723 # In the GDS context the script type ksh/csh is dependent from the login shell of the user.
679 724
680 725 if [ -n "${ENVSCRIPT}" ]
681 726 then
682 727 if [ -f ${ENVSCRIPT} ]
683 728 then
684 729 if ${GETENT} passwd ${USER} | ${AWK} -F: '{print $7}' | ${GREP} "csh" > /dev/null && [ -z "${SMF_FMRI}" ]
685 730 then
686 731 if ! /usr/bin/csh -n ${ENVSCRIPT} > /dev/null 2>&1
687 732 then
688 733 # SCMSGS
689 734 # @explanation
690 735 # The environment
691 736 # script spcified in
692 737 # the parameter file
693 738 # needs to be a valid
694 739 # c shell script,
695 740 # because the login
696 741 # shell of the
697 742 # PostgreSQL user is c
698 743 # shell compliant.
699 744 # @user_action
700 745 # Fix the environment
701 746 # script until it
702 747 # passes csh -n
703 748 # scriptname.
704 749 scds_syslog -p daemon.err -t $(syslog_tag) -m \
705 750 "Function: validate: The Environment script %s is not a valid c shell script" \
706 751 "${ENVSCRIPT}"
707 752 rc_validate=1
708 753 else
709 754 debug_message "Function: validate - ENVSCRIPT OK"
710 755 fi
711 756 else
712 757 if ! /usr/bin/ksh -n ${ENVSCRIPT} >/dev/null 2>&1
713 758 then
714 759 # SCMSGS
715 760 # @explanation
716 761 # The environment
717 762 # script spcified in
718 763 # the parameter file
719 764 # needs to be a valid
720 765 # korn shell script,
721 766 # because the login
|
↓ 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
850 984
851 985 debug_message "Function: validate_probe - Begin"
852 986 ${SET_DEBUG}
853 987
854 988 rc_val_probe=0
855 989
856 990 # If the parameter file does not pass the short validation, try a failover
857 991 # A failover is the appropriate action, because the directory existed
858 992 # at startup of the resource.
859 993
860 994 if ! val_parfile ${PARFILE}
|
↓ 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.
883 1017 # If this directory is not available, a failover will be initiated.
884 1018 # If it does not contain a / then it has to be a hostname or an address, in this case the hostname
885 1019 # has to respond to ping.
886 1020
887 1021 if [ -n "${PGHOST}" ]
888 1022 then
889 1023
890 1024 # strip of leading spaces
891 1025
892 1026 PGHOST=`print ${PGHOST}|${SED} 's/^ *//'`
893 1027
894 1028 if ${ECHO} ${PGHOST} | ${GREP} "^/" >/dev/null 2>&1
895 1029 then
896 1030
|
↓ 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
919 1053 # The test will detect accidentally unconfigured interfaces, just a failover or restart of
920 1054 # the resource group can cure this problem.
921 1055
922 1056 # This ping test is here to prevent a predictable timeout, it is needed as long as
923 1057 # SUNW.LogicalHost does not probe the ipaddresses. As soon as this changes the
924 1058 # ping test should be removed.
|
↓ 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
947 1081 }
948 1082
949 1083 val_parfile()
950 1084 {
951 1085 # Common valdation for parameter file
952 1086 #
953 1087 # If the parameter is in $2, there will be an intensive validation.
954 1088 # If $2 is empty, the validation will just check for the existance of the file.
955 1089
956 1090 debug_message "Function: val_parfile - Begin"
957 1091 ${SET_DEBUG}
958 1092
959 1093 rc_val_parfile=0
960 1094
961 1095 # Validate that parameter file exists
962 1096
963 1097 PARFILE=${1}
964 1098 PARLIST=${2}
965 1099
966 1100 if [ ! -f "${PARFILE}" ]; then
967 1101 # SCMSGS
968 1102 # @explanation
969 1103 # The parameter file does not exist in the parameter file
970 1104 # directory.
971 1105 # @user_action
972 1106 # Restore the parameter file or re-register the resource.
973 1107 scds_syslog -p daemon.err -t $(syslog_tag) -m \
974 1108 "Function: val_parfile - File %s does not exist" \
975 1109 "${PARFILE}"
976 1110 rc_val_parfile=1
977 1111 else
978 1112 debug_message "Function: val_parfile - ${PARFILE} exists"
979 1113 fi
980 1114
981 1115 # Test the semantics only, if the parameter list is specified.
982 1116 # This should not be done when called from validate_probe.
983 1117
984 1118 if [ -n "${2}" ]
985 1119 then
986 1120
987 1121 # Test if the parameter file is a valid ksh script
988 1122
989 1123 if ! ksh -n ${PARFILE} >/dev/null 2>&1
990 1124 then
991 1125 # SCMSGS
992 1126 # @explanation
993 1127 # The parameter file is not a valid shell script.
994 1128 # @user_action
995 1129 # Correct the parameter file. It must pass ksh -n <file name>.
996 1130 scds_syslog -p daemon.err -t $(syslog_tag) -m \
997 1131 "Function: validate - Syntax errors in %s" \
998 1132 "${PARFILE}"
999 1133 rc_val_parfile=1
1000 1134 else
1001 1135 debug_message "Function: val_parfile - validated ${PARFILE}"
1002 1136 fi
1003 1137
1004 1138 # Test if all the mandatory variables are included and set correctly in the parameter file
1005 1139
1006 1140 PARAMETERS=`${CAT} ${PARFILE} |grep -v "^#"|grep -v "^ "|nawk -F= '{print $1}'`
1007 1141
1008 1142 for i in ${PARLIST}
1009 1143 do
1010 1144 if ! `echo ${PARAMETERS} |grep ${i} > /dev/null `; then
1011 1145 # SCMSGS
1012 1146 # @explanation
1013 1147 # The referenced necessary parameter is not mentioned
1014 1148 # in the parameter file.
1015 1149 # @user_action
1016 1150 # Specify the parameter as a key value pair in the
1017 1151 # parameter file.
1018 1152 scds_syslog -p daemon.err -t $(syslog_tag) -m \
1019 1153 "Function: val_parfile - %s not specified in %s, which is required" \
1020 1154 "${i}" "${PARFILE}"
1021 1155 rc_val_parfile=1
1022 1156 else
1023 1157 debug_message "Function: val_parfile - ${i} included in ${PARFILE}"
1024 1158 fi
1025 1159 done
1026 1160 fi
1027 1161
1028 1162 debug_message "Function: val_parfile - End"
1029 1163 return ${rc_val_parfile}
1030 1164 }
1031 1165
1032 1166
1033 1167 Remove_shared_memory()
1034 1168 {
1035 1169 debug_message "Function: Remove_shared_memory - Start called with the following arguments "$*
1036 1170 ${SET_DEBUG}
1037 1171
1038 1172 User=$1
1039 1173
1040 1174 if [ -n "${DEBUG}" ]
1041 1175 then
1042 1176 debug_message "IPC Status of the current zone BEFORE removal of non-attached segments created by user ${User}"
1043 1177
1044 1178 # remove the logfile, before creating it to survive potential noclobber settings
1045 1179
1046 1180 ${RM} ${LOGFILE} 2>/dev/null
1047 1181 ${IPCS} -mcopb > ${LOGFILE}
1048 1182
1049 1183 log_message debug ipcs
1050 1184 ${RM} ${LOGFILE}
1051 1185 fi
1052 1186
1053 1187 ${IPCS} -mcopb |${GREP} " ${User} "| ${AWK} ' \
1054 1188 {if (NF == 12 && $9 == 0 ) print $2,$5,$6,$11,$12; else \
1055 1189 if (NF == 11 && $8 == 0 ) print $1,$4,$5,$10,$11 }' | \
1056 1190 while read SHMID SHMUSER GROUP CPID LPID
1057 1191 do
1058 1192 if ${PS} -p ${CPID} > /dev/null
1059 1193 then
1060 1194 debug_message "PostgresSQL SHMID: ${SHMID} - CPID ${CPID} is running"
1061 1195 else
1062 1196 if ${PS} -p ${LPID} > /dev/null
1063 1197 then
1064 1198 debug_message "PostgresSQL SHMID: ${SHMID} - LPID ${LPID} is running"
1065 1199 else
1066 1200 SHMID=`${ECHO} ${SHMID} | ${TR} 'm' ' '`
1067 1201 ${IPCRM} -m ${SHMID} > /dev/null
1068 1202 debug_message "PostgreSQL SHMID: ${SHMID} - removed"
1069 1203 flag=deleted
1070 1204 fi
1071 1205 fi
1072 1206 done
|
↓ 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}
1094 1228 fi
1095 1229
1096 1230 debug_message "Function: Remove_shared_memory - End"
|
↓ 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}
1117 1252
1118 1253 # remove shared memory which may be there from a killed postmaster
1119 1254
1120 1255 Remove_shared_memory ${USER}
1121 1256
1122 1257 # construct the necessary environment variables
1123 1258
1124 1259 LIBPATH=
1125 1260 if [ -n "${LD_LIBRARY_PATH}" ]
|
↓ 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
1171 1450 debug_message "Function: stop_pgs - Begin"
1172 1451 ${SET_DEBUG}
1173 1452
1174 1453 # construct the necessary redirection and source variables
1175 1454
1176 1455 set_shell_specifics
1177 1456
1178 1457 # Define the appropriate newtask command.
1179 1458 # The Project will be derived according to the call method,
1180 1459 # either from the smf service or from the cluster resource / resource group
1181 1460
1182 1461 srm_function ${USER}
1183 1462
1184 1463 # construct the necessary environment variables
1185 1464
1186 1465 LIBPATH=
1187 1466 if [ -n "${LD_LIBRARY_PATH}" ]
1188 1467 then
1189 1468 LIBPATH="${ENV} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
1190 1469 fi
1191 1470
1192 1471 PORT="PGPORT=${PGPORT}"
1193 1472 DATA="PGDATA=${PGDATA}"
1194 1473
1195 1474 # remember the process id of the parent postmaster
1196 1475
1197 1476 pgrspid=`${HEAD} -1 ${PGDATA}/postmaster.pid`
1198 1477
1199 1478 # remove the logfile, before creating it to survive potential noclobber settings
1200 1479
1201 1480 ${RM} ${LOGFILE} 2>/dev/null
1202 1481
1203 1482 # Perform a fast shutdown first. The server is specified by the triple user, PGPORT and the PGDATA variable.
1204 1483 # The fast shutdown will disconnect the clients and stop the server processes.
1205 1484
1206 1485 # SCMSGS
1207 1486 # @explanation
|
↓ 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
1290 1622 debug_message "Function: check_pgs - Begin"
1291 1623 ${SET_DEBUG}
1292 1624
1293 1625 rc_check_command=0
1294 1626
|
↓ 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}"
1344 1761 fi
1345 1762
1346 1763 # the variable PASSWORD is set to the database user login passowrd
1347 1764
1348 1765 PASSWORD=
1349 1766 if [ -n "${SCPASS}" ]
1350 1767 then
1351 1768 PASSWORD="${ENV} PGPASSWORD=${SCPASS}"
1352 1769 fi
1353 1770 PORT="PGPORT=${PGPORT}"
1354 1771 DATA="PGDATA=${PGDATA}"
1355 1772
1356 1773 if [ -n "${PGHOST}" ]
1357 1774 then
1358 1775 HOST="${ENV} PGHOST=${PGHOST}"
1359 1776 fi
1360 1777
1361 1778 # remove the temporary output files before creating them to survive potential noclobber settings
1362 1779
1363 1780 ${RM} /tmp/${RESOURCE}-${USER}-cat-out 2>/dev/null
1364 1781 ${RM} /tmp/${RESOURCE}-${USER}-cat-err 2>/dev/null
1365 1782 ${RM} /tmp/${RESOURCE}-${USER}-tbl-out 2>/dev/null
1366 1783 ${RM} /tmp/${RESOURCE}-${USER}-tbl-err 2>/dev/null
1367 1784
1368 1785 # construct the sql commands for the test
|
↓ 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 ]
1390 1807 then
1391 1808 cp /tmp/${RESOURCE}-${USER}-cat-err ${LOGFILE}
1392 1809 log_message err "check_pgs: rc<${NOCONRET}>"
1393 1810 fi
1394 1811
1395 1812 debug_message "Function: check_pgs - End"
1396 1813 rc_check_command=${NOCONRET}
1397 1814
1398 1815 else
1399 1816
1400 1817 # check if the test database is in the database catalog
1401 1818
1402 1819 if ! ${EGREP} " ${SCDB}$| ${SCDB} " /tmp/${RESOURCE}-${USER}-cat-out >/dev/null 2>&1
1403 1820 then
1404 1821
1405 1822 debug_message "Function: check_pgs - The test database ${SCDB} is not in the database catalog"
1406 1823
1407 1824 if [ ${wait_for_online} -eq 0 ]
1408 1825 then
1409 1826 # SCMSGS
1410 1827 # @explanation
1411 1828 # The database to monitor does not exist in
1412 1829 # the database catalog.
1413 1830 # @user_action
1414 1831 # Fix the parameter file to contain the right
1415 1832 # database name in the SCDB variable, or
1416 1833 # prepare the database.
1417 1834 scds_syslog -p daemon.err -t $(syslog_tag) -m \
1418 1835 "check_pgs: The test database %s is not in the database catalog" \
1419 1836 "${SCDB}"
1420 1837 fi
1421 1838
1422 1839 rc_check_command=100
1423 1840 else
1424 1841 debug_message "Function: check_pgs - check if the database catalog is accessible with ${SCDB} was successful"
1425 1842 fi
|
↓ 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 ]
1447 1864 then
1448 1865 cp /tmp/${RESOURCE}-${USER}-tbl-err ${LOGFILE}
1449 1866 log_message err "check_pgs: rc<${NOCONRET}>"
1450 1867 fi
1451 1868
1452 1869 rc_check_command=${NOCONRET}
1453 1870
1454 1871 else
1455 1872
1456 1873 # check if the test table could be manipulated successfully
1457 1874
1458 1875
1459 1876 if ! ${GREP} "hello im there" /tmp/${RESOURCE}-${USER}-tbl-out >/dev/null 2>&1
1460 1877 then
1461 1878
|
↓ 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