Add -e parameter to allow to specify expected replication state
This commit is contained in:
parent
a674949d93
commit
49648b04fc
1 changed files with 14 additions and 5 deletions
|
@ -41,10 +41,13 @@ PG_DB=""
|
||||||
CHECK_CUR_MASTER_LSN=1
|
CHECK_CUR_MASTER_LSN=1
|
||||||
REPLAY_WARNING_DELAY=3
|
REPLAY_WARNING_DELAY=3
|
||||||
REPLAY_CRITICAL_DELAY=5
|
REPLAY_CRITICAL_DELAY=5
|
||||||
|
EXPECTED_SYNC_STATE=sync
|
||||||
|
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
|
|
||||||
function usage () {
|
function usage () {
|
||||||
|
ERROR="$1"
|
||||||
|
[ -n "$ERROR" ] && echo -e "$ERROR\n"
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Usage: $0 [-d] [-h] [options]
|
Usage: $0 [-d] [-h] [options]
|
||||||
-u pg_user Specify local Postgres user (Default: try to auto-detect or use $DEFAULT_PG_USER)
|
-u pg_user Specify local Postgres user (Default: try to auto-detect or use $DEFAULT_PG_USER)
|
||||||
|
@ -64,13 +67,14 @@ Usage: $0 [-d] [-h] [options]
|
||||||
of the last received LSN (Default: $CHECK_CUR_MASTER_LSN)
|
of the last received LSN (Default: $CHECK_CUR_MASTER_LSN)
|
||||||
-w replay_warn_delay Specify the replay warning delay in second (Default: $REPLAY_WARNING_DELAY)
|
-w replay_warn_delay Specify the replay warning delay in second (Default: $REPLAY_WARNING_DELAY)
|
||||||
-c replay_crit_delay Specify the replay critical delay in second (Default: $REPLAY_CRITICAL_DELAY)
|
-c replay_crit_delay Specify the replay critical delay in second (Default: $REPLAY_CRITICAL_DELAY)
|
||||||
|
-e expected_sync_state The expected replication state ('sync' or 'async', default: $EXPECTED_SYNC_STATE)
|
||||||
-d Debug mode
|
-d Debug mode
|
||||||
-h Show this message
|
-h Show this message
|
||||||
EOF
|
EOF
|
||||||
exit 0
|
[ -n "$ERROR" ] && exit 1 || exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "hu:b:B:V:m:r:U:p:D:C:w:c:d" OPTION
|
while getopts "hu:b:B:V:m:r:U:p:D:C:w:c:e:d" OPTION
|
||||||
do
|
do
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
u)
|
u)
|
||||||
|
@ -109,6 +113,11 @@ do
|
||||||
c)
|
c)
|
||||||
REPLAY_CRITICAL_DELAY=$OPTARG
|
REPLAY_CRITICAL_DELAY=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
e)
|
||||||
|
[ "$OPTARG" != "sync" -a "$OPTARG" != "async" ] && \
|
||||||
|
usage "Invalid expected replication state '$OPTARG'. Possible values: sync or async."
|
||||||
|
EXPECTED_SYNC_STATE=$OPTARG
|
||||||
|
;;
|
||||||
d)
|
d)
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
;;
|
;;
|
||||||
|
@ -354,9 +363,9 @@ then
|
||||||
|
|
||||||
M_CUR_SYNC_STATE=$( echo "$M_CUR_REPL_STATE_INFO"|cut -d'|' -f2 )
|
M_CUR_SYNC_STATE=$( echo "$M_CUR_REPL_STATE_INFO"|cut -d'|' -f2 )
|
||||||
debug "Master current sync state: $M_CUR_SYNC_STATE"
|
debug "Master current sync state: $M_CUR_SYNC_STATE"
|
||||||
if [ "$M_CUR_SYNC_STATE" != "sync" ]
|
if [ "$M_CUR_SYNC_STATE" != "$EXPECTED_SYNC_STATE" ]
|
||||||
then
|
then
|
||||||
echo "CRITICAL: this host is not synchronized according to master host (current sync state = '$M_CUR_SYNC_STATE')"
|
echo "CRITICAL: unexpected replication state '$M_CUR_SYNC_STATE' (expected state = '$EXPECTED_SYNC_STATE')"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue