231
247
Number of shutdown retries (using -m fast) before resorting to -m immediate
233
249
<shortdesc lang="en">stop escalation</shortdesc>
234
<content type="integer" default="${OCF_RESKEY_stop_escalation}" />
250
<content type="integer" default="${OCF_RESKEY_stop_escalate_default}" />
253
<parameter name="rep_mode" unique="0" required="0">
255
Replication mode(none(default)/async/sync).
256
"async" and "sync" require PostgreSQL 9.1 or later.
257
If you use async or sync, it requires node_list, master_ip, restore_command
258
parameters, and needs setting postgresql.conf, pg_hba.conf up for
260
Please delete "include /../../rep_mode.conf" line in postgresql.conf
261
when you switch from sync to async.
263
<shortdesc lang="en">rep_mode</shortdesc>
264
<content type="string" default="${OCF_RESKEY_rep_mode_default}" />
267
<parameter name="node_list" unique="0" required="0">
269
All node names. Please separate each node name with a space.
270
This is required for replication.
272
<shortdesc lang="en">node list</shortdesc>
273
<content type="string" default="${OCF_RESKEY_node_list_default}" />
276
<parameter name="restore_command" unique="0" required="0">
278
restore_command for recovery.conf.
279
This is required for replication.
281
<shortdesc lang="en">restore_command</shortdesc>
282
<content type="string" default="${OCF_RESKEY_restore_command_default}" />
285
<parameter name="archive_cleanup_command" unique="0" required="0">
287
archive_cleanup_command for recovery.conf.
288
This is used for replication and is optional.
290
<shortdesc lang="en">archive_cleanup_command</shortdesc>
291
<content type="string" default="${OCF_RESKEY_archive_cleanup_command_default}" />
294
<parameter name="recovery_end_command" unique="0" required="0">
296
recovery_end_command for recovery.conf.
297
This is used for replication and is optional.
299
<shortdesc lang="en">recovery_end_command</shortdesc>
300
<content type="string" default="${OCF_RESKEY_recovery_end_command_default}" />
303
<parameter name="master_ip" unique="0" required="0">
305
Master's floating IP address to be connected from hot standby.
306
This parameter is used for "primary_conninfo" in recovery.conf.
307
This is required for replication.
309
<shortdesc lang="en">master ip</shortdesc>
310
<content type="string" default="${OCF_RESKEY_master_ip_default}" />
313
<parameter name="repuser" unique="0" required="0">
315
User used to connect to the master server.
316
This parameter is used for "primary_conninfo" in recovery.conf.
317
This is required for replication.
319
<shortdesc lang="en">repuser</shortdesc>
320
<content type="string" default="${OCF_RESKEY_repuser_default}" />
323
<parameter name="primary_conninfo_opt" unique="0" required="0">
325
primary_conninfo options of recovery.conf except host, port, user and application_name.
326
This is optional for replication.
328
<shortdesc lang="en">primary_conninfo_opt</shortdesc>
329
<content type="string" default="${OCF_RESKEY_primary_conninfo_opt_default}" />
332
<parameter name="tmpdir" unique="0" required="0">
334
Path to temporary directory.
335
This is optional for replication.
337
<shortdesc lang="en">tmpdir</shortdesc>
338
<content type="string" default="${OCF_RESKEY_tmpdir_default}" />
341
<parameter name="xlog_check_count" unique="0" required="0">
343
Number of checking xlog on monitor before promote.
344
This is optional for replication.
346
<shortdesc lang="en">xlog check count</shortdesc>
347
<content type="integer" default="${OCF_RESKEY_check_count_default}" />
350
<parameter name="crm_attr_timeout" unique="0" required="0">
352
The timeout of crm_attribute forever update command.
353
Default value is 5 seconds.
354
This is optional for replication.
356
<shortdesc lang="en">The timeout of crm_attribute forever update command.</shortdesc>
357
<content type="integer" default="${OCF_RESKEY_crm_attr_timeout_default}" />
360
<parameter name="stop_escalate_in_slave" unique="0" required="0">
362
Number of shutdown retries (using -m fast) before resorting to -m immediate
364
This is optional for replication.
366
<shortdesc lang="en">stop escalation_in_slave</shortdesc>
367
<content type="integer" default="${OCF_RESKEY_stop_escalate_in_slave_default}" />
336
480
pgctl_options="$OCF_RESKEY_ctl_opt -D $OCF_RESKEY_pgdata -l $OCF_RESKEY_logfile"
338
482
# Set options passed to the PostgreSQL server process
340
if [ -n "$OCF_RESKEY_config" ]; then
341
postgres_options="$postgres_options -c config_file=${OCF_RESKEY_config}"
483
postgres_options="-c config_file=${OCF_RESKEY_config}"
343
485
if [ -n "$OCF_RESKEY_pghost" ]; then
344
postgres_options="$postgres_options -h $OCF_RESKEY_pghost"
486
postgres_options="$postgres_options -h $OCF_RESKEY_pghost"
346
488
if [ -n "$OCF_RESKEY_start_opt" ]; then
347
postgres_options="$postgres_options $OCF_RESKEY_start_opt"
489
postgres_options="$postgres_options $OCF_RESKEY_start_opt"
350
492
# Tack pass-through options onto pg_ctl options
351
if [ -n "$postgres_options" ]; then
352
pgctl_options="$pgctl_options -o '$postgres_options'"
493
pgctl_options="$pgctl_options -o '$postgres_options'"
356
runasowner "$OCF_RESKEY_pgctl $pgctl_options start"
496
runasowner "unset PGUSER; unset PGPASSWORD; $OCF_RESKEY_pgctl $pgctl_options start"
358
498
if [ $? -eq 0 ]; then
359
# Probably started.....
499
# Probably started.....
360
500
ocf_log info "PostgreSQL start command sent."
362
ocf_log err "Can't start PostgreSQL."
502
ocf_log err "Can't start PostgreSQL."
363
503
return $OCF_ERR_GENERIC
508
pgsql_real_monitor warn
370
if [ $rc -eq 0 ]; then
510
if [ $rc -eq $OCF_SUCCESS -o $rc -eq $OCF_RUNNING_MASTER ]; then
374
ocf_log debug "PostgreSQL still hasn't started yet. Waiting..."
514
ocf_log debug "PostgreSQL still hasn't started yet. Waiting..."
376
517
ocf_log info "PostgreSQL is started."
381
#pgsql_stop: Stop PostgreSQL
521
pgsql_replication_start() {
524
# initializing for replication
525
change_pgsql_status "$NODENAME" "STOP"
526
delete_master_baseline
527
$CRM_MASTER -v $CAN_NOT_PROMOTE
528
rm -f ${XLOG_NOTE_FILE}.* $REP_MODE_CONF $RECOVERY_CONF
529
if ! make_recovery_conf || ! delete_xlog_location || ! set_async_mode_all; then
530
return $OCF_ERR_GENERIC
533
if [ -f $PGSQL_LOCK ]; then
534
ocf_log err "My data may be inconsistent. You have to remove $PGSQL_LOCK file to force start."
535
return $OCF_ERR_GENERIC
540
if [ $? -ne $OCF_SUCCESS ]; then
541
return $OCF_ERR_GENERIC
543
change_pgsql_status "$NODENAME" "HS:alone"
547
#pgsql_start: pgsql_real_start() wrapper for replication
549
if ! is_replication; then
553
pgsql_replication_start
558
#pgsql_promote: Promote PostgreSQL
563
if ! is_replication; then
564
ocf_log err "Not in a replication mode."
565
return $OCF_ERR_CONFIGURED
567
rm -f ${XLOG_NOTE_FILE}.*
569
for target in $NODE_LIST; do
570
[ "$target" = "$NODENAME" ] && continue
571
change_data_status "$target" "DISCONNECT"
572
change_master_score "$target" "$CAN_NOT_PROMOTE"
575
ocf_log info "Creating $PGSQL_LOCK."
579
runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata promote"
580
if [ $? -eq 0 ]; then
581
ocf_log info "PostgreSQL promote command sent."
583
ocf_log err "Can't promote PostgreSQL."
584
return $OCF_ERR_GENERIC
589
pgsql_real_monitor warn
591
if [ $rc -eq $OCF_RUNNING_MASTER ]; then
593
elif [ $rc -eq $OCF_ERR_GENERIC ]; then
594
ocf_log err "Can't promote PostgreSQL."
598
ocf_log debug "PostgreSQL still hasn't promoted yet. Waiting..."
600
ocf_log info "PostgreSQL is promoted."
602
change_data_status "$NODENAME" "LATEST"
603
$CRM_MASTER -v $PROMOTE_ME
604
change_pgsql_status "$NODENAME" "PRI"
608
#pgsql_demote: Demote PostgreSQL
612
if ! is_replication; then
613
ocf_log err "Not in a replication mode."
614
return $OCF_ERR_CONFIGURED
617
$CRM_MASTER -v $CAN_NOT_PROMOTE
618
delete_master_baseline
620
if ! pgsql_status; then
621
ocf_log info "PostgreSQL is already stopped on demote."
623
ocf_log info "Stopping PostgreSQL on demote."
624
pgsql_real_stop master
626
if [ "$rc" -ne "$OCF_SUCCESS" ]; then
627
change_pgsql_status "$NODENAME" "UNKNOWN"
631
change_pgsql_status "$NODENAME" "STOP"
635
#pgsql_real_stop: Stop PostgreSQL
385
641
if ! pgsql_status
756
pgsql_real_monitor() {
457
761
# Set the log level of the error message
458
762
loglevel=${1:-err}
460
764
if ! pgsql_status
462
ocf_log info "PostgreSQL is down"
463
return $OCF_NOT_RUNNING
466
if [ -n "$OCF_RESKEY_monitor_user" ]; then
467
PGUSER=$OCF_RESKEY_monitor_user; export PGUSER
468
PGPASSWORD=$OCF_RESKEY_monitor_password; export PGPASSWORD
469
psql_options="-p $OCF_RESKEY_pgport $OCF_RESKEY_pgdb"
471
psql_options="-p $OCF_RESKEY_pgport -U $OCF_RESKEY_pgdba $OCF_RESKEY_pgdb"
474
if [ -n "$OCF_RESKEY_pghost" ]; then
475
psql_options="$psql_options -h $OCF_RESKEY_pghost"
477
if [ -n "$OCF_RESKEY_socketdir" ]; then
478
psql_options="$psql_options -h $OCF_RESKEY_socketdir"
766
ocf_log info "PostgreSQL is down"
767
return $OCF_NOT_RUNNING
770
if is_replication; then
771
#Check replication state
772
output=`su $OCF_RESKEY_pgdba -c "cd $OCF_RESKEY_pgdata; \
773
$OCF_RESKEY_psql $psql_options -U $OCF_RESKEY_pgdba \
774
-Atc \"${CHECK_MS_SQL}\""`
776
if [ $rc -ne 0 ]; then
777
report_psql_error $rc $loglevel
778
return $OCF_ERR_GENERIC
782
f) ocf_log debug "PostgreSQL is running as a primary."
783
if [ "$OCF_RESKEY_monitor_sql" = "$OCF_RESKEY_monitor_sql_default" ]; then
784
return $OCF_RUNNING_MASTER
788
t) ocf_log debug "PostgreSQL is running as a hot standby."
789
return $OCF_SUCCESS;;
791
*) ocf_log err "$CHECK_MS_SQL output is $output"
792
return $OCF_ERR_GENERIC;;
482
796
OCF_RESKEY_monitor_sql=`escape_string "$OCF_RESKEY_monitor_sql"`
483
runasowner -q $loglevel "$OCF_RESKEY_psql $psql_options -c '$OCF_RESKEY_monitor_sql'"
797
runasowner -q $loglevel "$OCF_RESKEY_psql $psql_options \
798
-c '$OCF_RESKEY_monitor_sql'"
486
800
if [ $rc -ne 0 ]; then
487
ocf_log $loglevel "PostgreSQL $OCF_RESKEY_pgdb isn't running"
488
if [ $rc -eq 1 ]; then
489
ocf_log err "Fatal error (out of memory, file not found, etc.) occurred while executing the psql command."
490
elif [ $rc -eq 2 ]; then
491
ocf_log $loglevel "Connection error (connection to the server went bad and the session was not interactive) occurred while executing the psql command."
492
elif [ $rc -eq 3 ]; then
493
ocf_log err "Script error (the variable ON_ERROR_STOP was set) occurred while executing the psql command."
495
return $OCF_ERR_GENERIC
801
report_psql_error $rc $loglevel
802
return $OCF_ERR_GENERIC
805
if is_replication; then
806
return $OCF_RUNNING_MASTER
811
pgsql_replication_monitor() {
815
if [ $rc -ne $OCF_SUCCESS -a $rc -ne "$OCF_RUNNING_MASTER" ]; then
819
if [ $rc -eq $OCF_RUNNING_MASTER ]; then
820
change_data_status "$NODENAME" "LATEST"
821
change_pgsql_status "$NODENAME" "PRI"
822
control_slave_status || return $OCF_ERR_GENERIC
826
# I can't get master node name from $OCF_RESKEY_CRM_meta_notify_master_uname on monitor,
827
# so I will get master node name using crm_mon -n
828
crm_mon -n1 | tr -d "\t" | grep -q "^${RESOURCE_NAME}:.* Master"
829
if [ $? -ne 0 ] ; then
830
# If I am Slave and Master is not exist
831
ocf_log info "Master does not exist."
832
change_pgsql_status "$NODENAME" "HS:alone"
834
if [ $? -eq 0 ]; then
835
rm -f ${XLOG_NOTE_FILE}.*
838
output=`$CRM_ATTR_FOREVER -N "$NODENAME" \
839
-n "$PGSQL_DATA_STATUS_ATTR" -G -q`
840
if [ "$output" = "DISCONNECT" ]; then
841
change_pgsql_status "$NODENAME" "HS:alone"
847
#pgsql_monitor: pgsql_real_monitor() wrapper for replication
853
if ! is_replication; then
856
pgsql_replication_monitor $rc
862
pgsql_post_demote() {
863
DEMOTE_NODE=`echo $OCF_RESKEY_CRM_meta_notify_demote_uname | sed "s/ /\n/g" | head -1`
864
ocf_log debug "post-demote called. Demote uname is $DEMOTE_NODE"
865
if [ "$DEMOTE_NODE" != "$NODENAME" ]; then
866
if ! echo $OCF_RESKEY_CRM_meta_notify_master_uname | grep $NODENAME; then
868
change_pgsql_status "$NODENAME" "HS:alone"
874
pgsql_pre_promote() {
875
local master_baseline
876
local my_master_baseline
878
local number_of_nodes
880
# If my data is newer than new master's one, I fail my resource.
881
PROMOTE_NODE=`echo $OCF_RESKEY_CRM_meta_notify_promote_uname | \
882
sed "s/ /\n/g" | head -1`
883
number_of_nodes=`echo $NODE_LIST | wc -w`
884
if [ $number_of_nodes -ge 3 -a \
885
"$OCF_RESKEY_rep_mode" = "sync" -a \
886
"$PROMOTE_NODE" != "$NODENAME" ]; then
887
master_baseline=`$CRM_ATTR_REBOOT -N "$PROMOTE_NODE" -n \
888
"$PGSQL_MASTER_BASELINE" -G -q 2>/dev/null`
889
if [ $? -eq 0 ]; then
890
my_master_baseline=`$CRM_ATTR_REBOOT -N "$NODENAME" -n \
891
"$PGSQL_MASTER_BASELINE" -G -q 2>/dev/null`
893
cmp_location=`printf "$master_baseline\n$my_master_baseline\n" |\
895
if [ "$cmp_location" != "$my_master_baseline" ]; then
896
ocf_log err "My data is newer than new master's one. New master's location : $master_baseline"
897
$CRM_FAILCOUNT -r $OCF_RESOURCE_INSTANCE -U $NODENAME -v INFINITY
898
return $OCF_ERR_GENERIC
906
local type="${OCF_RESKEY_CRM_meta_notify_type}"
907
local op="${OCF_RESKEY_CRM_meta_notify_operation}"
910
if ! is_replication; then
914
ocf_log debug "notify: ${type} for ${op}"
928
PROMOTE_NODE=`echo $OCF_RESKEY_CRM_meta_notify_promote_uname | \
929
sed "s/ /\n/g" | head -1`
930
if [ "$PROMOTE_NODE" != "$NODENAME" ]; then
931
delete_master_baseline
940
if [ "$NODENAME " = "$OCF_RESKEY_CRM_meta_notify_master_uname" ]; then
951
control_slave_status() {
955
local all_data_status
956
local tmp_data_status
958
local number_of_nodes
960
all_data_status=`su $OCF_RESKEY_pgdba -c "cd $OCF_RESKEY_pgdata; \
961
$OCF_RESKEY_psql $psql_options -U $OCF_RESKEY_pgdba \
962
-Atc \"${CHECK_REPLICATION_STATE_SQL}\""`
964
if [ $rc -eq 0 ]; then
965
if [ -n "$all_data_status" ]; then
966
all_data_status=`echo $all_data_status | sed "s/\n/ /g"`
969
report_psql_error $rc warn
973
number_of_nodes=`echo $NODE_LIST | wc -w`
974
for target in $NODE_LIST; do
975
if [ "$target" = "$NODENAME" ]; then
979
data_status="DISCONNECT"
980
if [ -n "$all_data_status" ]; then
981
for tmp_data_status in $all_data_status; do
982
node_name=`echo $tmp_data_status | cut -d "|" -f 1`
983
state=`echo $tmp_data_status | cut -d "|" -f 2`
984
sync_state=`echo $tmp_data_status | cut -d "|" -f 3`
985
ocf_log debug "node=$node_name, state=$state, sync_state=$sync_state"
986
if [ "$node_name" = "$target" ];then
987
data_status="$state|$sync_state"
993
case "$data_status" in
995
change_data_status "$target" "$data_status"
996
change_master_score "$target" "$CAN_PROMOTE"
997
change_pgsql_status "$target" "HS:sync"
1000
change_data_status "$target" "$data_status"
1001
if [ "$OCF_RESKEY_rep_mode" = "sync" ]; then
1002
change_master_score "$target" "$CAN_NOT_PROMOTE"
1003
if ! is_sync_mode "$target"; then
1004
set_sync_mode "$target"
1007
if [ $number_of_nodes -le 2 ]; then
1008
change_master_score "$target" "$CAN_PROMOTE"
1010
# I can't determine which slave's data is newest in async mode.
1011
change_master_score "$target" "$CAN_NOT_PROMOTE"
1014
change_pgsql_status "$target" "HS:async"
1016
"STREAMING|POTENTIAL")
1017
change_data_status "$target" "$data_status"
1018
change_master_score "$target" "$CAN_NOT_PROMOTE"
1019
change_pgsql_status "$target" "HS:potential"
1022
change_data_status "$target" "$data_status"
1023
change_master_score "$target" "$CAN_NOT_PROMOTE"
1024
if [ "$OCF_RESKEY_rep_mode" = "sync" ] && \
1025
is_sync_mode "$target"; then
1026
set_async_mode "$target"
1030
change_data_status "$target" "$data_status"
1031
change_master_score "$target" "$CAN_NOT_PROMOTE"
1032
if [ "$OCF_RESKEY_rep_mode" = "sync" ] && \
1033
is_sync_mode "$target"; then
1034
set_async_mode "$target"
1036
change_pgsql_status "$target" "HS:connected"
1043
have_master_right() {
1055
ocf_log debug "Checking if I have a master right."
1057
data_status=`$CRM_ATTR_FOREVER -N "$NODENAME" -n \
1058
"$PGSQL_DATA_STATUS_ATTR" -G -q`
1059
if [ "$OCF_RESKEY_rep_mode" = "sync" ]; then
1060
if [ -n "$data_status" -a "$data_status" != "STREAMING|SYNC" -a \
1061
"$data_status" != "LATEST" ]; then
1062
ocf_log warn "My data is out-of-date. status=$data_status"
1066
if [ -n "$data_status" -a "$data_status" != "STREAMING|SYNC" -a \
1067
"$data_status" != "STREAMING|ASYNC" -a \
1068
"$data_status" != "LATEST" ]; then
1069
ocf_log warn "My data is out-of-date. status=$data_status"
1073
ocf_log info "My data status=$data_status."
1076
if [ $? -ne 0 ]; then
1077
ocf_log err "Failed to show my xlog location."
1078
exit $OCF_ERR_GENERIC
1082
for count in `seq $OCF_RESKEY_xlog_check_count`; do
1083
if [ -f ${XLOG_NOTE_FILE}.$count ]; then
1091
# get xlog locations of all nodes
1092
for node in ${NODE_LIST}; do
1093
output=`$CRM_ATTR_REBOOT -N "$node" -n \
1094
"$PGSQL_XLOG_LOC_NAME" -G -q 2>/dev/null`
1095
if [ $? -ne 0 ]; then
1096
ocf_log warn "Can't get $node xlog location."
1099
ocf_log info "$node xlog location : $output"
1100
echo "$node $output" >> ${XLOG_NOTE_FILE}.${new}
1101
if [ "$node" = "$NODENAME" ]; then
1107
oldfile=`cat ${XLOG_NOTE_FILE}.${old} 2>/dev/null`
1108
newfile=`cat ${XLOG_NOTE_FILE}.${new} 2>/dev/null`
1109
if [ "$oldfile" != "$newfile" ]; then
1111
rm -f ${XLOG_NOTE_FILE}.*
1112
printf "$newfile\n" > ${XLOG_NOTE_FILE}.0
1116
if [ "$new" -ge "$OCF_RESKEY_xlog_check_count" ]; then
1117
newestXlog=`printf "$newfile\n" | sort -t " " -k 2,3 -r | \
1118
head -1 | cut -d " " -f 2`
1119
if [ "$newestXlog" = "$mylocation" ]; then
1120
ocf_log info "I have a master right."
1121
$CRM_MASTER -v $PROMOTE_ME
1124
change_data_status "$NODENAME" "DISCONNECT"
1125
ocf_log info "I don't have correct master data."
1127
rm -f ${XLOG_NOTE_FILE}.*
1128
printf "$newfile\n" > ${XLOG_NOTE_FILE}.0
1135
if [ "$OCF_RESKEY_rep_mode" != "none" ]; then
1150
local newer_location
1152
output=`su $OCF_RESKEY_pgdba -c "cd $OCF_RESKEY_pgdata; \
1153
$OCF_RESKEY_psql $psql_options -U $OCF_RESKEY_pgdba \
1154
-Atc \"${CHECK_XLOG_LOC_SQL}\""`
1156
if [ $rc -ne 0 ]; then
1157
report_psql_error $rc warn
1158
ocf_log err "Can't get my xlog location."
1161
replay_loc=`echo $output | cut -d "|" -f 1`
1162
receive_loc=`echo $output | cut -d "|" -f 2`
1164
output1=`echo "$replay_loc" | cut -d "/" -f 1`
1165
output2=`echo "$replay_loc" | cut -d "/" -f 2`
1166
log1=`printf "%08s\n" $output1 | sed "s/ /0/g"`
1167
log2=`printf "%08s\n" $output2 | sed "s/ /0/g"`
1168
replay_loc="${log1}${log2}"
1170
output1=`echo "$receive_loc" | cut -d "/" -f 1`
1171
output2=`echo "$receive_loc" | cut -d "/" -f 2`
1172
log1=`printf "%08s\n" $output1 | sed "s/ /0/g"`
1173
log2=`printf "%08s\n" $output2 | sed "s/ /0/g"`
1174
receive_loc="${log1}${log2}"
1176
newer_location=`printf "$replay_loc\n$receive_loc" | sort -r | head -1`
1177
echo "$newer_location"
1181
show_xlog_location() {
1184
location=`get_my_location` || return 1
1185
$CRM_ATTR_REBOOT -N "$NODENAME" -n "$PGSQL_XLOG_LOC_NAME" -v "$location"
1188
delete_xlog_location() {
1189
$CRM_ATTR_REBOOT -N "$NODENAME" -n "$PGSQL_XLOG_LOC_NAME" -D
1192
show_master_baseline() {
1196
runasowner -q err "$OCF_RESKEY_psql $psql_options \
1197
-U $OCF_RESKEY_pgdba -c 'CHECKPOINT'"
1199
if [ $rc -ne 0 ]; then
1200
report_psql_error $rc warn
1202
location=`get_my_location`
1203
ocf_log info "My master baseline : $location."
1204
$CRM_ATTR_REBOOT -N "$NODENAME" -n "$PGSQL_MASTER_BASELINE" -v "$location"
1207
delete_master_baseline() {
1208
$CRM_ATTR_REBOOT -N "$NODENAME" -n "$PGSQL_MASTER_BASELINE" -D
1211
set_async_mode_all() {
1212
[ "$OCF_RESKEY_rep_mode" = "sync" ] || return 0
1213
ocf_log info "Set all nodes into async mode."
1214
runasowner -q err "echo \"synchronous_standby_names = ''\" > \"$REP_MODE_CONF\""
1215
if [ $? -ne 0 ]; then
1216
ocf_log err "Can't set all nodes into async mode."
1223
local sync_node_in_conf
1225
sync_node_in_conf=`cat $REP_MODE_CONF | cut -d "'" -f 2`
1226
if [ -n "$sync_node_in_conf" ]; then
1227
ocf_log info "Setup $1 into async mode."
1228
sync_node_in_conf=`echo $sync_node_in_conf | sed "s/$1//g" |\
1229
sed "s/^,//g" | sed "s/,,/,/g" | sed "s/,$//g"`
1230
echo "synchronous_standby_names = '$sync_node_in_conf'" > "$REP_MODE_CONF"
1232
ocf_log info "$1 is already in async mode."
1236
ocf_log info "All synced nodes : \"$sync_node_in_conf\""
1241
local sync_node_in_conf
1243
sync_node_in_conf=`cat $REP_MODE_CONF | cut -d "'" -f 2`
1244
if [ -n "$sync_node_in_conf" ]; then
1245
ocf_log info "Setup $1 into sync mode."
1246
echo "synchronous_standby_names = '$sync_node_in_conf,$1'" > "$REP_MODE_CONF"
1248
ocf_log info "Setup $1 into sync mode."
1249
echo "synchronous_standby_names = '$1'" > "$REP_MODE_CONF"
1252
sync_node_in_conf=`cat $REP_MODE_CONF | cut -d "'" -f 2`
1253
ocf_log info "All synced nodes : \"$sync_node_in_conf\""
1258
cat $REP_MODE_CONF | grep -q -e "[,' ]$1[,' ]"
1263
runasowner "$OCF_RESKEY_pgctl -D $OCF_RESKEY_pgdata reload"
1264
if [ $? -eq 0 ]; then
1265
ocf_log info "Reload configuration file."
1267
ocf_log err "Can't reload configuration file."
1274
user_recovery_conf() {
1275
# put archive_cleanup_command and recovery_end_command only when defined by user
1276
if [ -n "$OCF_RESKEY_archive_cleanup_command" ]; then
1277
echo "archive_cleanup_command = '${OCF_RESKEY_archive_cleanup_command}'"
1279
if [ -n "$OCF_RESKEY_recovery_end_command" ]; then
1280
echo "recovery_end_command = '${OCF_RESKEY_recovery_end_command}'"
1284
make_recovery_conf() {
1285
runasowner "touch $RECOVERY_CONF"
1286
if [ $? -ne 0 ]; then
1287
ocf_log err "Can't create recovery.conf."
1291
cat > $RECOVERY_CONF <<END
1293
primary_conninfo = 'host=${OCF_RESKEY_master_ip} port=${OCF_RESKEY_pgport} user=${OCF_RESKEY_repuser} application_name=${NODENAME} ${OCF_RESKEY_primary_conninfo_opt}'
1294
restore_command = '${OCF_RESKEY_restore_command}'
1295
recovery_target_timeline = 'latest'
1298
user_recovery_conf >> $RECOVERY_CONF
1299
ocf_log debug "Created recovery.conf. host=${OCF_RESKEY_master_ip}, user=${OCF_RESKEY_repuser}"
1303
# change pgsql-status.
1304
# arg1:node, arg2: value
1305
change_pgsql_status() {
1308
if ! is_node_online $1; then
1312
output=`$CRM_ATTR_REBOOT -N "$1" -n "$PGSQL_STATUS_ATTR" -G -q 2>/dev/null`
1313
if [ "$output" != "$2" ]; then
1314
# If slave's disk is broken, RA cannot read PID file
1315
# and misjudges the PostgreSQL as down while it is running.
1316
# It causes overwriting of pgsql-status by Master because replication is still connected.
1317
if [ "$output" = "STOP" -o "$output" = "UNKNOWN" ]; then
1318
if [ "$1" != "$NODENAME" ]; then
1319
ocf_log warn "Changing $PGSQL_STATUS_ATTR on $1 : $output->$2 by $NODENAME is prohibited."
1323
ocf_log info "Changing $PGSQL_STATUS_ATTR on $1 : $output->$2."
1324
$CRM_ATTR_REBOOT -N "$1" -n "$PGSQL_STATUS_ATTR" -v "$2"
1325
if [ $? -ne 0 ]; then
1326
ocf_log err "Can't change $PGSQL_STATUS_ATTR."
1333
# change pgsql-data-status.
1334
# arg1:node, arg2: value
1335
change_data_status() {
1338
if ! node_exist $1; then
1344
output=`$CRM_ATTR_FOREVER -N "$1" -n "$PGSQL_DATA_STATUS_ATTR" -G -q 2>/dev/null`
1345
if [ "$output" != "$2" ]; then
1346
ocf_log info "Changing $PGSQL_DATA_STATUS_ATTR on $1 : $output->$2."
1347
exec_func_with_timeout "$CRM_ATTR_FOREVER" "-N $1 -n \
1348
$PGSQL_DATA_STATUS_ATTR -v \"$2\"" \
1349
$OCF_RESKEY_crm_attr_timeout
1350
if [ $? -ne 0 ]; then
1351
ocf_log err "Can't change $PGSQL_DATA_STATUS_ATTR."
1361
# change master-score
1362
# arg1:node, arg2: score
1363
change_master_score() {
1367
if ! is_node_online $1; then
1374
if [ "$instance" -ge "$OCF_RESKEY_CRM_meta_clone_max" ]; then
1377
if [ "${RESOURCE_NAME}:${instance}" = "$OCF_RESOURCE_INSTANCE" ]; then
1378
instance=`expr $instance + 1`
1382
current_score=`$CRM_ATTR_REBOOT -N "$1" -n "master-${RESOURCE_NAME}:${instance}" -G -q 2>/dev/null`
1383
if [ -n "$current_score" -a "$current_score" != "$2" ]; then
1384
ocf_log info "Changing ${RESOURCE_NAME}:${instance} master score on $1 : $current_score->$2."
1385
$CRM_ATTR_REBOOT -N "$target" -n "master-${RESOURCE_NAME}:${instance}" -v "$2"
1386
if [ $? -ne 0 ]; then
1387
ocf_log err "Can't change master score."
1391
instance=`expr $instance + 1`
1404
ocf_log $loglevel "PostgreSQL $OCF_RESKEY_pgdb isn't running"
1405
if [ $rc -eq 1 ]; then
1406
ocf_log err "Fatal error (out of memory, file not found, etc.) occurred while executing the psql command."
1407
elif [ $rc -eq 2 ]; then
1408
ocf_log $loglevel "Connection error (connection to the server went bad and the session was not interactive) occurred while executing the psql command."
1409
elif [ $rc -eq 3 ]; then
1410
ocf_log err "Script error (the variable ON_ERROR_STOP was set) occurred while executing the psql command."
1415
# timeout management function
1417
# arg2 : command's args
1420
exec_func_with_timeout() {
1428
while kill -s 0 $func_pid >/dev/null 2>&1; do
1430
count=`expr $count + 1`
1431
if [ $count -ge $3 ]; then
1432
ocf_log debug "Execute $1 time out."
1433
kill -s 9 $func_pid >/dev/null 2>&1
1441
crm_mon -1 -n | grep -e "^Node $1 " -e "^Node $1:" | grep -q -v "OFFLINE"
1445
crm_mon -1 -n | grep -q "^Node $1"
501
1448
check_binary2() {