Remove spaces before colon (:)

This commit is contained in:
Benjamin Renard 2020-11-04 15:41:04 +01:00 committed by root
parent c8e6c80dc0
commit d4cbdb3c79

View file

@ -47,7 +47,7 @@ DEBUG=0
function usage () {
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)
-b psql_bin Specify psql binary path (Default: $PSQL_BIN)
-B pg_lsclusters_bin Specify pg_lsclusters binary path (Default: $PG_LSCLUSTER_BIN)
@ -129,7 +129,7 @@ function debug() {
fi
}
debug "Starting options (before handling auto-detection/default values) :
debug "Starting options (before handling auto-detection/default values):
PG_VERSION = $PG_VERSION
PG_DB = $PG_DB
PG_USER = $PG_USER
@ -169,21 +169,21 @@ fi
[ -z "$PG_DEFAULT_PORT" ] && PG_DEFAULT_PORT="$DEFAULT_PG_PORT"
# Check PG_USER
[ -z "$PG_USER" ] && echo "UNKNOWN : Postgres user not specified" && exit 3
[ -z "$PG_USER" ] && echo "UNKNOWN: Postgres user not specified" && exit 3
id "$PG_USER" > /dev/null 2>&1
[ $? -ne 0 ] && echo "UNKNOWN : Invalid Postgres user ($PG_USER)" && exit 3
[ $? -ne 0 ] && echo "UNKNOWN: Invalid Postgres user ($PG_USER)" && exit 3
# Check PSQL_BIN
[ ! -x "$PSQL_BIN" ] && echo "UNKNOWN : Invalid psql bin path ($PSQL_BIN)" && exit 3
[ ! -x "$PSQL_BIN" ] && echo "UNKNOWN: Invalid psql bin path ($PSQL_BIN)" && exit 3
# Check PG_MAIN
[ ! -d "$PG_MAIN/" ] && echo "UNKNOWN : Invalid Postgres main directory path ($PG_MAIN)" && exit 3
[ ! -d "$PG_MAIN/" ] && echo "UNKNOWN: Invalid Postgres main directory path ($PG_MAIN)" && exit 3
# Check RECOVERY_CONF
[ -z "$RECOVERY_CONF" ] && RECOVERY_CONF="$PG_MAIN/$RECOVERY_CONF_FILENAME"
# Check PG_DEFAULT_PORT
[ $( echo "$PG_DEFAULT_PORT"|grep -c -E '^[0-9]*$' ) -ne 1 ] && "UNKNOWN : Postgres default master TCP port must be an integer." && exit 3
[ $( echo "$PG_DEFAULT_PORT"|grep -c -E '^[0-9]*$' ) -ne 1 ] && "UNKNOWN: Postgres default master TCP port must be an integer." && exit 3
# If PG_DB is not provided with -D parameter, use PG_USER as default value
[ -z "$PG_DB" ] && PG_DB="$PG_USER"
@ -200,7 +200,7 @@ function psql_master_get () {
echo "$sql"|sudo -u $PG_USER $PSQL_BIN -U $M_USER -h $M_HOST -w -p $M_PORT -d $PG_DB -t -P format=unaligned
}
debug "Running options :
debug "Running options:
PG_VERSION = $PG_VERSION
PG_DB = $PG_DB
PG_USER = $PG_USER
@ -242,7 +242,7 @@ else
fi
if [ $? -ne 0 ]
then
echo "CRITICAL : Postgres is not running !"
echo "CRITICAL: Postgres is not running !"
exit 2
fi
debug "Postgres is running"
@ -257,89 +257,89 @@ then
# Check recovery mode
if [ $RECOVERY_MODE -ne 1 ]
then
echo "CRITICAL : Not in recovery mode while recovery.conf file found !"
echo "CRITICAL: Not in recovery mode while recovery.conf file found !"
exit 2
fi
debug "Postgres is in recovery mode"
LAST_XLOG_RECEIVE=$( psql_get "SELECT $pg_last_wal_receive_lsn" )
debug "Last xlog file receive : $LAST_XLOG_RECEIVE"
debug "Last xlog file receive: $LAST_XLOG_RECEIVE"
LAST_XLOG_REPLAY=$( psql_get "SELECT $pg_last_wal_replay_lsn" )
debug "Last xlog file replay : $LAST_XLOG_REPLAY"
debug "Last xlog file replay: $LAST_XLOG_REPLAY"
# Get master connection informations from recovery.conf file
MASTER_CONN_INFOS=$( egrep '^ *primary_conninfo' $RECOVERY_CONF|sed "s/^ *primary_conninfo *= *\(.\+\) *$/\1/" )
if [ ! -n "$MASTER_CONN_INFOS" ]
then
echo "UNKNOWN : Can't retreive master connection informations form recovery.conf file"
echo "UNKNOWN: Can't retreive master connection informations form recovery.conf file"
exit 3
fi
debug "Master connection informations : $MASTER_CONN_INFOS"
debug "Master connection informations: $MASTER_CONN_INFOS"
M_HOST=$( echo "$MASTER_CONN_INFOS"| grep 'host=' | sed 's/^.*host= *\([0-9a-zA-Z.-]\+\) *.*$/\1/' )
if [ ! -n "$M_HOST" ]
then
echo "UNKNOWN : Can't retreive master host from recovery.conf file"
echo "UNKNOWN: Can't retreive master host from recovery.conf file"
exit 3
fi
debug "Master host : $M_HOST"
debug "Master host: $M_HOST"
M_PORT=$( echo "$MASTER_CONN_INFOS"| grep 'port=' | sed 's/^.*port= *\([0-9a-zA-Z.-]\+\) *.*$/\1/' )
if [ ! -n "$M_PORT" ]
then
debug "Master port not specified, use default : $PG_DEFAULT_PORT"
debug "Master port not specified, use default: $PG_DEFAULT_PORT"
M_PORT=$PG_DEFAULT_PORT
else
debug "Master port : $M_PORT"
debug "Master port: $M_PORT"
fi
if [ -n "$PG_MASTER_USER" ]
then
debug "Master user provided by command-line, use it : $PG_MASTER_USER"
debug "Master user provided by command-line, use it: $PG_MASTER_USER"
M_USER="$PG_MASTER_USER"
else
M_USER=$( echo "$MASTER_CONN_INFOS"| grep 'user=' | sed 's/^.*user= *\([0-9a-zA-Z.-]\+\) *.*$/\1/' )
if [ ! -n "$M_USER" ]
then
debug "Master user not specified, use default : $PG_USER"
debug "Master user not specified, use default: $PG_USER"
M_USER=$PG_USER
else
debug "Master user : $M_USER"
debug "Master user: $M_USER"
fi
fi
M_APP_NAME=$( echo "$MASTER_CONN_INFOS"| grep 'application_name=' | sed "s/^.*application_name=[ \'\"]*\([^ \'\"]\+\)[ \'\"]*.*$/\1/" )
if [ ! -n "$M_APP_NAME" ]
then
debug "Master application name not specified, use default : $PG_DEFAULT_APP_NAME"
debug "Master application name not specified, use default: $PG_DEFAULT_APP_NAME"
M_APP_NAME=$PG_DEFAULT_APP_NAME
else
debug "Master application name : $M_APP_NAME"
debug "Master application name: $M_APP_NAME"
fi
# Get current state information from master
M_CUR_REPL_STATE_INFO="$( psql_master_get "SELECT state, sync_state FROM pg_stat_replication WHERE application_name='$M_APP_NAME';" )"
if [ ! -n "$M_CUR_REPL_STATE_INFO" ]
then
echo "UNKNOWN : Can't retreive current replication state information from master server"
echo "UNKNOWN: Can't retreive current replication state information from master server"
exit 3
fi
debug "Master current replication state:\n\tstate|sync_state\n\t$M_CUR_REPL_STATE_INFO"
M_CUR_STATE=$( echo "$M_CUR_REPL_STATE_INFO"|cut -d'|' -f1 )
debug "Master current state : $M_CUR_STATE"
debug "Master current state: $M_CUR_STATE"
if [ "$M_CUR_STATE" != "streaming" ]
then
echo "CRITICAL : this host is not in streaming state according to master host (current state = '$M_CUR_STATE')"
echo "CRITICAL: this host is not in streaming state according to master host (current state = '$M_CUR_STATE')"
exit 2
fi
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" ]
then
echo "CRITICAL : this host is not synchronized according to master host (current sync state = '$M_CUR_SYNC_STATE')"
echo "CRITICAL: this host is not synchronized according to master host (current sync state = '$M_CUR_SYNC_STATE')"
exit 2
fi
@ -350,15 +350,15 @@ then
M_CUR_XLOG="$( psql_master_get 'SELECT pg_current_xlog_location()' )"
if [ ! -n "$M_CUR_XLOG" ]
then
echo "UNKNOWN : Can't retreive current xlog from master server"
echo "UNKNOWN: Can't retreive current xlog from master server"
exit 3
fi
debug "Master current xlog : $M_CUR_XLOG"
debug "Master current xlog: $M_CUR_XLOG"
# Master current xlog is the last receive xlog ?
if [ "$M_CUR_XLOG" != "$LAST_XLOG_RECEIVE" ]
then
echo "CRITICAL : Master current xlog is not the last receive xlog"
echo "CRITICAL: Master current xlog is not the last receive xlog"
exit 2
fi
debug "Master current xlog is the last receive xlog"
@ -372,19 +372,19 @@ then
debug "Replay delay is $REPLAY_DELAY second(s)"
if [ $( echo "$REPLAY_DELAY >= $REPLAY_CRITICAL_DELAY"|bc -l ) -gt 0 ]
then
echo "CRITICAL : last receive xlog file is not the last replay file ('$LAST_XLOG_RECEIVE' / '$LAST_XLOG_REPLAY') and replay delay is $REPLAY_DELAY second(s)"
echo "CRITICAL: last receive xlog file is not the last replay file ('$LAST_XLOG_RECEIVE' / '$LAST_XLOG_REPLAY') and replay delay is $REPLAY_DELAY second(s)"
exit 2
fi
if [ $( echo "$REPLAY_DELAY >= $REPLAY_WARNING_DELAY"|bc -l ) -gt 0 ]
then
echo "WARNING : last receive xlog file is not the last replay file ('$LAST_XLOG_RECEIVE' / '$LAST_XLOG_REPLAY') and replay delay is $REPLAY_DELAY second(s)"
echo "WARNING: last receive xlog file is not the last replay file ('$LAST_XLOG_RECEIVE' / '$LAST_XLOG_REPLAY') and replay delay is $REPLAY_DELAY second(s)"
exit 1
fi
debug "Replay delay is not worrying"
fi
debug "Last receive xlog file is the last replay file"
echo "OK : Hot-standby server is uptodate"
echo "OK: Hot-standby server is uptodate"
exit 0
else
debug "File recovery.conf not found. Master mode."
@ -392,7 +392,7 @@ else
# Check recovery mode
if [ $RECOVERY_MODE -eq 1 ]
then
echo "CRITICAL : In recovery mode while recovery.conf file not found !"
echo "CRITICAL: In recovery mode while recovery.conf file not found !"
exit 2
fi
debug "Postgres is not in recovery mode"
@ -409,7 +409,7 @@ else
) AS s1" )
if [ ! -n "$STANDBY_CLIENTS" ]
then
echo "WARNING : no stand-by client connected"
echo "WARNING: no stand-by client connected"
exit 1
fi
debug "Stand-by client(s):\n\t$( echo -e "$STANDBY_CLIENTS"|sed 's/\n/\n\t/' )"
@ -430,6 +430,6 @@ else
STANDBY_CLIENTS_TXT="$STANDBY_CLIENTS_TXT\n$NAME ($IP): $STATE/$SYNC_STATE (Location: sent='$SENT_LOCATION' / write='$WRITE_LOCATION', Lag: ${LAG}b)"
done
echo -e "OK : $STANDBY_CLIENTS_COUNT stand-by client(s) connected\n$STANDBY_CLIENTS_TXT"
echo -e "OK: $STANDBY_CLIENTS_COUNT stand-by client(s) connected\n$STANDBY_CLIENTS_TXT"
exit 0
fi