Sdiff functions.ksh


3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the License). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/CDDL.txt 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/CDDL.txt. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets [] replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 27 #ident "%Z%%M% %I% %E% SMI" 28 29 PKG=SUNWscPostgreSQL 30 METHOD=`basename $0` 31 TASK_COMMAND="" 32 33 ZONENAME=/usr/bin/zonename 34 DIRNAME=/usr/bin/dirname 35 36 SCLOGGER=/usr/cluster/lib/sc/scds_syslog 37 PMFADM=/usr/cluster/bin/pmfadm 38 GETENT=/usr/bin/getent 39 AWK=/usr/bin/awk 40 NAWK=/usr/bin/nawk 41 CAT=/usr/bin/cat 42 EGREP=/usr/bin/egrep 43 GREP=/usr/bin/grep 44 ENV=/usr/bin/env 45 HEAD=/usr/bin/head 46 PS=/usr/bin/ps 47 PGREP=/usr/bin/pgrep 48 KILL=/usr/bin/kill 49 IPCS=/usr/bin/ipcs 50 IPCRM=/usr/bin/ipcrm 51 ECHO=/usr/bin/echo 52 TR=/usr/bin/tr 53 SU=/usr/bin/su 54 RM=/usr/bin/rm 55 ZLOGIN=/usr/sbin/zlogin 56 TEST=/usr/bin/test 57 PING=/usr/sbin/ping 58 SED=/usr/bin/sed 59 IFCONFIG=/usr/sbin/ifconfig 60 61 get_fmri_parameters () 62 { 63 64 # extract the smf properties, you need to call your agent commands 65 66 debug_message "Function: get_fmri_parameters - Begin " 67 ${SET_DEBUG} 68 69 # Resource name 70 71 RESOURCE=`/usr/bin/svcprop -p parameters/Resource ${SMF_FMRI}` 72 73 # Resource Group 74 75 RESOURCEGROUP=`/usr/bin/svcprop -p parameters/Resource_group ${SMF_FMRI}` 76 77 # Start Project 78 79 Project=:default
242 # for the generic data service. The value has to be between 1 and 100. 243 # 100/NOCONRET defines the number of consecutive probes to ignore for failed 244 # connections. A restart or failover will occur, if the number is exeeded within 245 # the retry interval. 246 247 248 USER=${USER} 249 PGROOT=${PGROOT} 250 PGDATA=${PGDATA} 251 PGPORT=${PGPORT} 252 PGHOST=${PGHOST} 253 PGLOGFILE=${PGLOGFILE} 254 LD_LIBRARY_PATH=${LD_LIBRARY_PATH} 255 ENVSCRIPT=${ENVSCRIPT} 256 SCDB=${SCDB} 257 SCUSER=${SCUSER} 258 SCTABLE=${SCTABLE} 259 SCPASS=${SCPASS} 260 NOCONRET=${NOCONRET} 261 262 EOF 263 if [ $? -ne 0 ] 264 then 265 ${ECHO} "ERROR: could not create the temporary parameter file ${pfile_tmp}" 266 return 1 267 fi 268 269 # create the parameter file either in the global or in the prepared target zone 270 271 if [ -n "${target_zone}" ] 272 then 273 ${CAT} ${pfile_tmp} | ${zonecmd} ${CAT} - \>${PFILE} 274 if [ $? -ne 0 ] 275 then 276 ${ECHO} "ERROR: could not create the parameter file ${PFILE}" 277 return 1 278 fi 279 else 280 ${CAT} ${pfile_tmp} > ${PFILE} 281 if [ $? -ne 0 ]
820 rc_validate=1 821 else 822 if [ ${NOCONRET} -gt 100 ]; then 823 # SCMSGS 824 # @explanation 825 # The value of the NOCONRET 826 # variable in the parameter 827 # file exeeds 100. 828 # @user_action 829 # Fix the parameter file with 830 # a value below 100. 831 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 832 "Function: validate: Return code for failed connections %s is greater 100" \ 833 "${NOCONRET}" 834 rc_validate=1 835 else 836 debug_message "Function: validate - NOCONRET OK" 837 fi 838 fi 839 fi;; 840 esac 841 done 842 843 debug_message "Function: validate - End" 844 return ${rc_validate} 845 } 846 847 validate_probe() 848 { 849 # Validate ony for non existant files or lost directories 850 851 debug_message "Function: validate_probe - Begin" 852 ${SET_DEBUG} 853 854 rc_val_probe=0 855 856 # If the parameter file does not pass the short validation, try a failover 857 # A failover is the appropriate action, because the directory existed 858 # at startup of the resource. 859
1087 then 1088 debug_message "IPC Status AFTER removal of non-attached segments created by user ${User}" 1089 1090 ${IPCS} -mcopb > ${LOGFILE} 1091 1092 log_message debug ipcs 1093 $RM ${LOGFILE} 1094 fi 1095 1096 debug_message "Function: Remove_shared_memory - End" 1097 } 1098 1099 start_pgs() 1100 { 1101 # 1102 # Start PostgreSQL 1103 # 1104 1105 debug_message "Function: start_pgs - Begin" 1106 ${SET_DEBUG} 1107 1108 # construct the necessary redirection and source variables 1109 1110 set_shell_specifics 1111 1112 # Define the appropriate newtask command. 1113 # The Project will be derived according to the call method, 1114 # either from the smf service or from the cluster resource / resource group 1115 1116 srm_function ${USER} 1117 1118 # remove shared memory which may be there from a killed postmaster 1119 1120 Remove_shared_memory ${USER} 1121 1122 # construct the necessary environment variables 1123 1124 LIBPATH= 1125 if [ -n "${LD_LIBRARY_PATH}" ] 1126 then 1127 LIBPATH="${ENV} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" 1128 fi 1129 1130 PORT="PGPORT=${PGPORT}" 1131 DATA="PGDATA=${PGDATA}" 1132 1133 # remove the logfile, before creating it to survive potential noclobber settings 1134 1135 ${RM} ${LOGFILE} 2>/dev/null 1136 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 # 1143 1144 if [ -z "${SMF_FMRI}" ] 1145 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 1149 1150 # start under the right user in an smf manifest you source a ksh script, regardless of the users login shell 1151 1152 if [ -n "${ENVSCRIPT}" ] 1153 then 1154 . ${ENVSCRIPT} 1155 fi 1156 1157 ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl start -l ${PGLOGFILE} >${LOGFILE} 2>&1 1158 rc_start_command=$? 1159 fi 1160 1161 debug_message "Function: start_pgs - End" 1162 return ${rc_start_command} 1163 } 1164 1165 stop_pgs() 1166 { 1167 # 1168 # Stop PostgreSQL 1169 # 1170 1171 debug_message "Function: stop_pgs - Begin" 1172 ${SET_DEBUG} 1173 1174 # construct the necessary redirection and source variables 1175 1176 set_shell_specifics 1177 1178 # Define the appropriate newtask command. 1179 # The Project will be derived according to the call method, 1180 # either from the smf service or from the cluster resource / resource group
1198 1199 # remove the logfile, before creating it to survive potential noclobber settings 1200 1201 ${RM} ${LOGFILE} 2>/dev/null 1202 1203 # Perform a fast shutdown first. The server is specified by the triple user, PGPORT and the PGDATA variable. 1204 # The fast shutdown will disconnect the clients and stop the server processes. 1205 1206 # SCMSGS 1207 # @explanation 1208 # The PostgreSQL database server is shut down with the specified 1209 # option. 1210 # @user_action 1211 # None 1212 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 1213 "stop_pgs: Stop PostgreSQL with the option %s " \ 1214 "fast" 1215 1216 if [ -z "${SMF_FMRI}" ] 1217 then 1218 ${SU} - ${USER} -c " ${ENVSC} ${TASK_COMMAND} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m fast ${OUTPUT}" > /dev/null 1219 rc_stop_command=$? 1220 else 1221 1222 # stop under the right user in a smf manifest 1223 1224 if [ -n "${ENVSCRIPT}" ] 1225 then 1226 . ${ENVSCRIPT} 1227 fi 1228 1229 ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m fast >${LOGFILE} 2>&1 1230 rc_stop_command=$? 1231 fi 1232 1233 # Determine if postgres is really stopped, if not perform an immediate shutdown. 1234 # 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. 1236 1237 if ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null 1238 then 1239 1240 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 1241 "stop_pgs: Stop PostgreSQL with the option %s " \ 1242 "immediate" 1243 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 1249 1250 # stop under the right user in a smf manifest 1251 1252 if [ -n "${ENVSCRIPT}" ] 1253 then 1254 . ${ENVSCRIPT} 1255 fi 1256 1257 ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m immediate >>${LOGFILE} 2>&1 1258 rc_stop_command=$? 1259 fi 1260 fi 1261 1262 # determine if postgres is really stopped, if not kill the parent of the postmaster with -9 1263 1264 if ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null 1265 then 1266 # SCMSGS 1267 # @explanation 1268 # The previous stop attempts for PostgreSQL failed. The server 1269 # is now killed with kill -9. 1270 # @user_action 1271 # None 1272 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 1273 "stop_pgs: Stop PostgreSQL process %s with kill -9 " \ 1274 "${pgrspid}" 1275 1276 ${KILL} -9 ${pgrspid} 1277 rc_stop_command=$? 1278 fi 1279 1280 debug_message "Function: stop_pgs - End" 1281 return ${rc_stop_command} 1282 } 1283 1284 check_pgs() 1285 { 1286 # 1287 # Probe PostgreSQL 1288 # 1289 1290 debug_message "Function: check_pgs - Begin" 1291 ${SET_DEBUG} 1292 1293 rc_check_command=0 1294 1295 # construct the necessary redirection and source variables 1296 1297 set_shell_specifics 1298 1299 # Define the appropriate newtask command. 1300 # The Project will be derived according to the call method, 1301 # either from the smf service or from the cluster resource / resource group 1302 1303 srm_function ${USER} 1304 1305 # Determine if the gds start process is already completed, or the database start is far enough to allow connections 1306 # The criteria is the existence of the postmaster.pid file in the PGDATA directory. 1307 # As long as the GDS start is not complete, probe error messages will be suppressed. 1308 1309 wait_for_online=0 1310 1311 ${PGREP} -u root -f "gds_svc_start .*-R ${RESOURCE} " >/dev/null 1312 if [ ${?} -eq 0 ] 1313 then 1314 debug_message "Function: check_pgs - wait for online detected" 1315 wait_for_online=1 1316 if [ -f ${PGDATA}/postmaster.pid ] 1317 then 1318 pgrspid=`${HEAD} -1 ${PGDATA}/postmaster.pid` 1319 if ! ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null 1320 then 1321 debug_message "Function: check_pgs - wait for online detected, postmaster is not running" 1322 rc_check_command=100 1323 else 1324 debug_message "Function: check_pgs - wait for online detected, postmaster is running proceed with normal checks" 1325 fi 1326 else 1327 debug_message "Function: check_pgs - wait for online detected, postmaster pid file ${PGDATA}/postmaster.pid not found" 1328 rc_check_command=100 1329 fi 1330 fi 1331 1332 if [ ${rc_check_command} -ne 0 ] 1333 then 1334 debug_message "Function: check_pgs - End" 1335 return ${rc_check_command} 1336 fi 1337 1338 # construct the necessary environment variables 1339 1340 LIBPATH= 1341 if [ -n "${LD_LIBRARY_PATH}" ] 1342 then 1343 LIBPATH="${ENV} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" 1344 fi 1345 1346 # the variable PASSWORD is set to the database user login passowrd 1347 1348 PASSWORD= 1349 if [ -n "${SCPASS}" ] 1350 then 1351 PASSWORD="${ENV} PGPASSWORD=${SCPASS}" 1352 fi 1353 PORT="PGPORT=${PGPORT}"
1359 fi 1360 1361 # remove the temporary output files before creating them to survive potential noclobber settings 1362 1363 ${RM} /tmp/${RESOURCE}-${USER}-cat-out 2>/dev/null 1364 ${RM} /tmp/${RESOURCE}-${USER}-cat-err 2>/dev/null 1365 ${RM} /tmp/${RESOURCE}-${USER}-tbl-out 2>/dev/null 1366 ${RM} /tmp/${RESOURCE}-${USER}-tbl-err 2>/dev/null 1367 1368 # construct the sql commands for the test 1369 1370 DBCAT="select datname from pg_database" 1371 DBTRUNC="truncate ${SCTABLE}" 1372 DBINS="insert into ${SCTABLE} (sccol) values('hello im there')" 1373 DBSEL="select * from ${SCTABLE}" 1374 1375 # check if the catalog of the postgres database is accessible 1376 1377 debug_message "Function: check_pgs - check if the database catalog is accessible with ${SCDB} " 1378 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 1380 rc_check_command=$? 1381 1382 # Return ${NOCONRET} if the connect fails, otherwise proceed with the check 1383 1384 if [ ${rc_check_command} -ne 0 ] 1385 then 1386 1387 debug_message "Function: check_pgs - connect to database ${SCDB} failed" 1388 1389 if [ ${wait_for_online} -eq 0 ] 1390 then 1391 cp /tmp/${RESOURCE}-${USER}-cat-err ${LOGFILE} 1392 log_message err "check_pgs: rc<${NOCONRET}>" 1393 fi 1394 1395 debug_message "Function: check_pgs - End" 1396 rc_check_command=${NOCONRET} 1397 1398 else 1399
1416 # prepare the database. 1417 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 1418 "check_pgs: The test database %s is not in the database catalog" \ 1419 "${SCDB}" 1420 fi 1421 1422 rc_check_command=100 1423 else 1424 debug_message "Function: check_pgs - check if the database catalog is accessible with ${SCDB} was successful" 1425 fi 1426 fi 1427 1428 # manipulate the table SCTABLE and exit 100 if the inserted string is not there, exit 10 if the connection to 1429 # the database fails 1430 1431 if [ ${rc_check_command} -eq 0 ] 1432 then 1433 1434 debug_message "Function: check_pgs - manipulate the table ${SCTABLE}" 1435 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 1437 rc_check_command=$? 1438 1439 # Return ${NOCONRET} if the connect fails, otherwise proceed with the check 1440 1441 if [ ${rc_check_command} -ne 0 ] 1442 then 1443 1444 debug_message "Function: check_pgs - connect to database ${SCDB} failed" 1445 1446 if [ ${wait_for_online} -eq 0 ] 1447 then 1448 cp /tmp/${RESOURCE}-${USER}-tbl-err ${LOGFILE} 1449 log_message err "check_pgs: rc<${NOCONRET}>" 1450 fi 1451 1452 rc_check_command=${NOCONRET} 1453 1454 else 1455 1456 # check if the test table could be manipulated successfully 1457 1458 1459 if ! ${GREP} "hello im there" /tmp/${RESOURCE}-${USER}-tbl-out >/dev/null 2>&1 1460 then 1461 1462 if [ ${wait_for_online} -eq 0 ] 1463 then 1464 # SCMSGS 1465 # @explanation 1466 # The monitoring action on the 1467 # specified table failed. 1468 # @user_action 1469 # None 1470 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 1471 "check_pgs: The test database manipulation failed for database %s, user %s and table %s" \ 1472 "${SCDB}" "${SCUSER}" "$SCTABLE}" 1473 fi 1474 1475 rc_check_command=100 1476 debug_message "Function: check_pgs - manipulation of the table ${SCTABLE} failed" 1477 1478 else 1479 1480 debug_message "Function: check_pgs - manipulation of the table ${SCTABLE} successful" 1481 1482 fi 1483 fi 1484 fi 1485 1486 debug_message "Function: check_pgs - End" 1487 return ${rc_check_command} 1488 }


3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the License). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/CDDL.txt 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/CDDL.txt. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets [] replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 27 # ident "%Z%%M% %I% %E% SMI" 28 29 PKG=SUNWscPostgreSQL 30 METHOD=`basename $0` 31 TASK_COMMAND="" 32 33 ZONENAME=/usr/bin/zonename 34 DIRNAME=/usr/bin/dirname 35 36 SCLOGGER=/usr/cluster/lib/sc/scds_syslog 37 PMFADM=/usr/cluster/bin/pmfadm 38 GETENT=/usr/bin/getent 39 AWK=/usr/bin/awk 40 NAWK=/usr/bin/nawk 41 CAT=/usr/bin/cat 42 EGREP=/usr/bin/egrep 43 GREP=/usr/bin/grep 44 ENV=/usr/bin/env 45 HEAD=/usr/bin/head 46 PS=/usr/bin/ps 47 PGREP=/usr/bin/pgrep 48 KILL=/usr/bin/kill 49 IPCS=/usr/bin/ipcs 50 IPCRM=/usr/bin/ipcrm 51 ECHO=/usr/bin/echo 52 TR=/usr/bin/tr 53 SU=/usr/bin/su 54 RM=/usr/bin/rm 55 ZLOGIN=/usr/sbin/zlogin 56 TEST=/usr/bin/test 57 PING=/usr/sbin/ping 58 SED=/usr/bin/sed 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 68 69 get_fmri_parameters () 70 { 71 72 # extract the smf properties, you need to call your agent commands 73 74 debug_message "Function: get_fmri_parameters - Begin " 75 ${SET_DEBUG} 76 77 # Resource name 78 79 RESOURCE=`/usr/bin/svcprop -p parameters/Resource ${SMF_FMRI}` 80 81 # Resource Group 82 83 RESOURCEGROUP=`/usr/bin/svcprop -p parameters/Resource_group ${SMF_FMRI}` 84 85 # Start Project 86 87 Project=:default
250 # for the generic data service. The value has to be between 1 and 100. 251 # 100/NOCONRET defines the number of consecutive probes to ignore for failed 252 # connections. A restart or failover will occur, if the number is exeeded within 253 # the retry interval. 254 255 256 USER=${USER} 257 PGROOT=${PGROOT} 258 PGDATA=${PGDATA} 259 PGPORT=${PGPORT} 260 PGHOST=${PGHOST} 261 PGLOGFILE=${PGLOGFILE} 262 LD_LIBRARY_PATH=${LD_LIBRARY_PATH} 263 ENVSCRIPT=${ENVSCRIPT} 264 SCDB=${SCDB} 265 SCUSER=${SCUSER} 266 SCTABLE=${SCTABLE} 267 SCPASS=${SCPASS} 268 NOCONRET=${NOCONRET} 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 307 EOF 308 if [ $? -ne 0 ] 309 then 310 ${ECHO} "ERROR: could not create the temporary parameter file ${pfile_tmp}" 311 return 1 312 fi 313 314 # create the parameter file either in the global or in the prepared target zone 315 316 if [ -n "${target_zone}" ] 317 then 318 ${CAT} ${pfile_tmp} | ${zonecmd} ${CAT} - \>${PFILE} 319 if [ $? -ne 0 ] 320 then 321 ${ECHO} "ERROR: could not create the parameter file ${PFILE}" 322 return 1 323 fi 324 else 325 ${CAT} ${pfile_tmp} > ${PFILE} 326 if [ $? -ne 0 ]
865 rc_validate=1 866 else 867 if [ ${NOCONRET} -gt 100 ]; then 868 # SCMSGS 869 # @explanation 870 # The value of the NOCONRET 871 # variable in the parameter 872 # file exeeds 100. 873 # @user_action 874 # Fix the parameter file with 875 # a value below 100. 876 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 877 "Function: validate: Return code for failed connections %s is greater 100" \ 878 "${NOCONRET}" 879 rc_validate=1 880 else 881 debug_message "Function: validate - NOCONRET OK" 882 fi 883 fi 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;; 974 esac 975 done 976 977 debug_message "Function: validate - End" 978 return ${rc_validate} 979 } 980 981 validate_probe() 982 { 983 # Validate ony for non existant files or lost directories 984 985 debug_message "Function: validate_probe - Begin" 986 ${SET_DEBUG} 987 988 rc_val_probe=0 989 990 # If the parameter file does not pass the short validation, try a failover 991 # A failover is the appropriate action, because the directory existed 992 # at startup of the resource. 993
1221 then 1222 debug_message "IPC Status AFTER removal of non-attached segments created by user ${User}" 1223 1224 ${IPCS} -mcopb > ${LOGFILE} 1225 1226 log_message debug ipcs 1227 $RM ${LOGFILE} 1228 fi 1229 1230 debug_message "Function: Remove_shared_memory - End" 1231 } 1232 1233 start_pgs() 1234 { 1235 # 1236 # Start PostgreSQL 1237 # 1238 1239 debug_message "Function: start_pgs - Begin" 1240 ${SET_DEBUG} 1241 SECONDS=0 1242 1243 # construct the necessary redirection and source variables 1244 1245 set_shell_specifics 1246 1247 # Define the appropriate newtask command. 1248 # The Project will be derived according to the call method, 1249 # either from the smf service or from the cluster resource / resource group 1250 1251 srm_function ${USER} 1252 1253 # remove shared memory which may be there from a killed postmaster 1254 1255 Remove_shared_memory ${USER} 1256 1257 # construct the necessary environment variables 1258 1259 LIBPATH= 1260 if [ -n "${LD_LIBRARY_PATH}" ] 1261 then 1262 LIBPATH="${ENV} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" 1263 fi 1264 1265 PORT="PGPORT=${PGPORT}" 1266 DATA="PGDATA=${PGDATA}" 1267 1268 # remove the logfile, before creating it to survive potential noclobber settings 1269 1270 ${RM} ${LOGFILE} 2>/dev/null 1271 1272 do_start=0 1273 1274 # start an ssh-agent and store the decrypted private key if SSH_PASSDIR is configured 1275 1276 1277 if [ -n "${SSH_PASSDIR}" ] 1278 then 1279 1280 ${CP} -p ${SSH_PASSDIR}/${RESOURCE}-phrase /tmp/${RESOURCE}-phrase 1281 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 1297 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 ] 1305 then 1306 SOCK=`${GREP} SSH_AUTH_SOCK /tmp/${RESOURCE}-ssh` 1307 SOCK="${ENV} ${SOCK}" 1308 fi 1309 fi 1310 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 1370 fi 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 1440 debug_message "Function: start_pgs - End" 1441 return ${rc_start_command} 1442 } 1443 1444 stop_pgs() 1445 { 1446 # 1447 # Stop PostgreSQL 1448 # 1449 1450 debug_message "Function: stop_pgs - Begin" 1451 ${SET_DEBUG} 1452 1453 # construct the necessary redirection and source variables 1454 1455 set_shell_specifics 1456 1457 # Define the appropriate newtask command. 1458 # The Project will be derived according to the call method, 1459 # either from the smf service or from the cluster resource / resource group
1477 1478 # remove the logfile, before creating it to survive potential noclobber settings 1479 1480 ${RM} ${LOGFILE} 2>/dev/null 1481 1482 # Perform a fast shutdown first. The server is specified by the triple user, PGPORT and the PGDATA variable. 1483 # The fast shutdown will disconnect the clients and stop the server processes. 1484 1485 # SCMSGS 1486 # @explanation 1487 # The PostgreSQL database server is shut down with the specified 1488 # option. 1489 # @user_action 1490 # None 1491 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 1492 "stop_pgs: Stop PostgreSQL with the option %s " \ 1493 "fast" 1494 1495 if [ -z "${SMF_FMRI}" ] 1496 then 1497 ${SU} ${USER} -c " ${ENVSC} ${TASK_COMMAND} ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m fast ${OUTPUT}" > /dev/null 1498 rc_stop_command=$? 1499 else 1500 1501 # stop under the right user in a smf manifest 1502 1503 if [ -n "${ENVSCRIPT}" ] 1504 then 1505 . ${ENVSCRIPT} 1506 fi 1507 1508 ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m fast >${LOGFILE} 2>&1 1509 rc_stop_command=$? 1510 fi 1511 1512 # Determine if postgres is really stopped, if not perform an immediate shutdown. 1513 # The server is specified by the triple user, PGPORT and the PGDATA variable. 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. 1517 1518 1519 if [ ! -f ${PGDATA}/recovery.conf ] 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 1533 1534 # stop under the right user in a smf manifest 1535 1536 if [ -n "${ENVSCRIPT}" ] 1537 then 1538 . ${ENVSCRIPT} 1539 fi 1540 1541 ${LIBPATH} ${ENV} ${DATA} ${ENV} ${PORT} ${PGROOT}/bin/pg_ctl stop -m immediate >>${LOGFILE} 2>&1 1542 rc_stop_command=$? 1543 fi 1544 fi 1545 else 1546 debug_message "Function: stop_pgs - It is a standby database, do not stop with immediate" 1547 fi 1548 1549 # determine if postgres is really stopped, if not kill the parent of the postmaster with -9 1550 1551 if ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null 1552 then 1553 # SCMSGS 1554 # @explanation 1555 # The previous stop attempts for PostgreSQL failed. The server 1556 # is now killed with kill -9. 1557 # @user_action 1558 # None 1559 scds_syslog -p daemon.notice -t $(syslog_tag) -m \ 1560 "stop_pgs: Stop PostgreSQL process %s with kill -9 " \ 1561 "${pgrspid}" 1562 1563 ${KILL} -9 ${pgrspid} 1564 rc_stop_command=$? 1565 fi 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 1612 debug_message "Function: stop_pgs - End" 1613 return ${rc_stop_command} 1614 } 1615 1616 check_pgs() 1617 { 1618 # 1619 # Probe PostgreSQL 1620 # 1621 1622 debug_message "Function: check_pgs - Begin" 1623 ${SET_DEBUG} 1624 1625 rc_check_command=0 1626 1627 # construct the necessary redirection and source variables 1628 1629 set_shell_specifics 1630 1631 # Define the appropriate newtask command. 1632 # The Project will be derived according to the call method, 1633 # either from the smf service or from the cluster resource / resource group 1634 1635 srm_function ${USER} 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 1654 # Determine if the gds start process is already completed, or the database start is far enough to allow connections 1655 # The criteria is the existence of the postmaster.pid file in the PGDATA directory. 1656 # As long as the GDS start is not complete, probe error messages will be suppressed. 1657 1658 wait_for_online=0 1659 1660 ${PGREP} -u root -f "gds_svc_start .*-R ${RESOURCE} " >/dev/null 1661 if [ ${?} -eq 0 ] 1662 then 1663 debug_message "Function: check_pgs - wait for online detected" 1664 wait_for_online=1 1665 if [ -n "${pgrspid}" ] 1666 then 1667 if ! ${PS} -u ${USER} -o pid,ppid |${GREP} -w ${pgrspid}>/dev/null 1668 then 1669 debug_message "Function: check_pgs - wait for online detected, postmaster is not running" 1670 rc_check_command=100 1671 else 1672 debug_message "Function: check_pgs - wait for online detected, postmaster is running proceed with normal checks" 1673 fi 1674 else 1675 debug_message "Function: check_pgs - wait for online detected, postmaster pid file ${PGDATA}/postmaster.pid not found" 1676 rc_check_command=100 1677 fi 1678 fi 1679 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}" ] 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 1751 debug_message "Function: check_pgs - End" 1752 return ${rc_check_command} 1753 fi 1754 1755 # construct the necessary environment variables 1756 1757 LIBPATH= 1758 if [ -n "${LD_LIBRARY_PATH}" ] 1759 then 1760 LIBPATH="${ENV} LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" 1761 fi 1762 1763 # the variable PASSWORD is set to the database user login passowrd 1764 1765 PASSWORD= 1766 if [ -n "${SCPASS}" ] 1767 then 1768 PASSWORD="${ENV} PGPASSWORD=${SCPASS}" 1769 fi 1770 PORT="PGPORT=${PGPORT}"
1776 fi 1777 1778 # remove the temporary output files before creating them to survive potential noclobber settings 1779 1780 ${RM} /tmp/${RESOURCE}-${USER}-cat-out 2>/dev/null 1781 ${RM} /tmp/${RESOURCE}-${USER}-cat-err 2>/dev/null 1782 ${RM} /tmp/${RESOURCE}-${USER}-tbl-out 2>/dev/null 1783 ${RM} /tmp/${RESOURCE}-${USER}-tbl-err 2>/dev/null 1784 1785 # construct the sql commands for the test 1786 1787 DBCAT="select datname from pg_database" 1788 DBTRUNC="truncate ${SCTABLE}" 1789 DBINS="insert into ${SCTABLE} (sccol) values('hello im there')" 1790 DBSEL="select * from ${SCTABLE}" 1791 1792 # check if the catalog of the postgres database is accessible 1793 1794 debug_message "Function: check_pgs - check if the database catalog is accessible with ${SCDB} " 1795 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 1797 rc_check_command=$? 1798 1799 # Return ${NOCONRET} if the connect fails, otherwise proceed with the check 1800 1801 if [ ${rc_check_command} -ne 0 ] 1802 then 1803 1804 debug_message "Function: check_pgs - connect to database ${SCDB} failed" 1805 1806 if [ ${wait_for_online} -eq 0 ] 1807 then 1808 cp /tmp/${RESOURCE}-${USER}-cat-err ${LOGFILE} 1809 log_message err "check_pgs: rc<${NOCONRET}>" 1810 fi 1811 1812 debug_message "Function: check_pgs - End" 1813 rc_check_command=${NOCONRET} 1814 1815 else 1816
1833 # prepare the database. 1834 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 1835 "check_pgs: The test database %s is not in the database catalog" \ 1836 "${SCDB}" 1837 fi 1838 1839 rc_check_command=100 1840 else 1841 debug_message "Function: check_pgs - check if the database catalog is accessible with ${SCDB} was successful" 1842 fi 1843 fi 1844 1845 # manipulate the table SCTABLE and exit 100 if the inserted string is not there, exit 10 if the connection to 1846 # the database fails 1847 1848 if [ ${rc_check_command} -eq 0 ] 1849 then 1850 1851 debug_message "Function: check_pgs - manipulate the table ${SCTABLE}" 1852 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 1854 rc_check_command=$? 1855 1856 # Return ${NOCONRET} if the connect fails, otherwise proceed with the check 1857 1858 if [ ${rc_check_command} -ne 0 ] 1859 then 1860 1861 debug_message "Function: check_pgs - connect to database ${SCDB} failed" 1862 1863 if [ ${wait_for_online} -eq 0 ] 1864 then 1865 cp /tmp/${RESOURCE}-${USER}-tbl-err ${LOGFILE} 1866 log_message err "check_pgs: rc<${NOCONRET}>" 1867 fi 1868 1869 rc_check_command=${NOCONRET} 1870 1871 else 1872 1873 # check if the test table could be manipulated successfully 1874 1875 1876 if ! ${GREP} "hello im there" /tmp/${RESOURCE}-${USER}-tbl-out >/dev/null 2>&1 1877 then 1878 1879 if [ ${wait_for_online} -eq 0 ] 1880 then 1881 # SCMSGS 1882 # @explanation 1883 # The monitoring action on the 1884 # specified table failed. 1885 # @user_action 1886 # None 1887 scds_syslog -p daemon.err -t $(syslog_tag) -m \ 1888 "check_pgs: The test database manipulation failed for database %s, user %s and table %s" \ 1889 "${SCDB}" "${SCUSER}" "${SCTABLE}" 1890 fi 1891 1892 rc_check_command=100 1893 debug_message "Function: check_pgs - manipulation of the table ${SCTABLE} failed" 1894 1895 else 1896 1897 debug_message "Function: check_pgs - manipulation of the table ${SCTABLE} successful" 1898 1899 fi 1900 fi 1901 fi 1902 1903 debug_message "Function: check_pgs - End" 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} 1998 }