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 () { function usage () {
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)
-b psql_bin Specify psql binary path (Default: $PSQL_BIN) -b psql_bin Specify psql binary path (Default: $PSQL_BIN)
-B pg_lsclusters_bin Specify pg_lsclusters binary path (Default: $PG_LSCLUSTER_BIN) -B pg_lsclusters_bin Specify pg_lsclusters binary path (Default: $PG_LSCLUSTER_BIN)
@ -129,7 +129,7 @@ function debug() {
fi fi
} }
debug "Starting options (before handling auto-detection/default values) : debug "Starting options (before handling auto-detection/default values):
PG_VERSION = $PG_VERSION PG_VERSION = $PG_VERSION
PG_DB = $PG_DB PG_DB = $PG_DB
PG_USER = $PG_USER PG_USER = $PG_USER
@ -169,21 +169,21 @@ fi
[ -z "$PG_DEFAULT_PORT" ] && PG_DEFAULT_PORT="$DEFAULT_PG_PORT" [ -z "$PG_DEFAULT_PORT" ] && PG_DEFAULT_PORT="$DEFAULT_PG_PORT"
# Check PG_USER # 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 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 # 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 # 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 # Check RECOVERY_CONF
[ -z "$RECOVERY_CONF" ] && RECOVERY_CONF="$PG_MAIN/$RECOVERY_CONF_FILENAME" [ -z "$RECOVERY_CONF" ] && RECOVERY_CONF="$PG_MAIN/$RECOVERY_CONF_FILENAME"
# Check PG_DEFAULT_PORT # 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 # If PG_DB is not provided with -D parameter, use PG_USER as default value
[ -z "$PG_DB" ] && PG_DB="$PG_USER" [ -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 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_VERSION = $PG_VERSION
PG_DB = $PG_DB PG_DB = $PG_DB
PG_USER = $PG_USER PG_USER = $PG_USER
@ -242,7 +242,7 @@ else
fi fi
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
echo "CRITICAL : Postgres is not running !" echo "CRITICAL: Postgres is not running !"
exit 2 exit 2
fi fi
debug "Postgres is running" debug "Postgres is running"
@ -257,89 +257,89 @@ then
# Check recovery mode # Check recovery mode
if [ $RECOVERY_MODE -ne 1 ] if [ $RECOVERY_MODE -ne 1 ]
then 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 exit 2
fi fi
debug "Postgres is in recovery mode" debug "Postgres is in recovery mode"
LAST_XLOG_RECEIVE=$( psql_get "SELECT $pg_last_wal_receive_lsn" ) 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" ) 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 # Get master connection informations from recovery.conf file
MASTER_CONN_INFOS=$( egrep '^ *primary_conninfo' $RECOVERY_CONF|sed "s/^ *primary_conninfo *= *\(.\+\) *$/\1/" ) MASTER_CONN_INFOS=$( egrep '^ *primary_conninfo' $RECOVERY_CONF|sed "s/^ *primary_conninfo *= *\(.\+\) *$/\1/" )
if [ ! -n "$MASTER_CONN_INFOS" ] if [ ! -n "$MASTER_CONN_INFOS" ]
then 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 exit 3
fi 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/' ) M_HOST=$( echo "$MASTER_CONN_INFOS"| grep 'host=' | sed 's/^.*host= *\([0-9a-zA-Z.-]\+\) *.*$/\1/' )
if [ ! -n "$M_HOST" ] if [ ! -n "$M_HOST" ]
then 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 exit 3
fi 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/' ) M_PORT=$( echo "$MASTER_CONN_INFOS"| grep 'port=' | sed 's/^.*port= *\([0-9a-zA-Z.-]\+\) *.*$/\1/' )
if [ ! -n "$M_PORT" ] if [ ! -n "$M_PORT" ]
then 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 M_PORT=$PG_DEFAULT_PORT
else else
debug "Master port : $M_PORT" debug "Master port: $M_PORT"
fi fi
if [ -n "$PG_MASTER_USER" ] if [ -n "$PG_MASTER_USER" ]
then 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" M_USER="$PG_MASTER_USER"
else else
M_USER=$( echo "$MASTER_CONN_INFOS"| grep 'user=' | sed 's/^.*user= *\([0-9a-zA-Z.-]\+\) *.*$/\1/' ) M_USER=$( echo "$MASTER_CONN_INFOS"| grep 'user=' | sed 's/^.*user= *\([0-9a-zA-Z.-]\+\) *.*$/\1/' )
if [ ! -n "$M_USER" ] if [ ! -n "$M_USER" ]
then then
debug "Master user not specified, use default : $PG_USER" debug "Master user not specified, use default: $PG_USER"
M_USER=$PG_USER M_USER=$PG_USER
else else
debug "Master user : $M_USER" debug "Master user: $M_USER"
fi fi
fi fi
M_APP_NAME=$( echo "$MASTER_CONN_INFOS"| grep 'application_name=' | sed "s/^.*application_name=[ \'\"]*\([^ \'\"]\+\)[ \'\"]*.*$/\1/" ) M_APP_NAME=$( echo "$MASTER_CONN_INFOS"| grep 'application_name=' | sed "s/^.*application_name=[ \'\"]*\([^ \'\"]\+\)[ \'\"]*.*$/\1/" )
if [ ! -n "$M_APP_NAME" ] if [ ! -n "$M_APP_NAME" ]
then 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 M_APP_NAME=$PG_DEFAULT_APP_NAME
else else
debug "Master application name : $M_APP_NAME" debug "Master application name: $M_APP_NAME"
fi fi
# Get current state information from master # 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';" )" 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" ] if [ ! -n "$M_CUR_REPL_STATE_INFO" ]
then 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 exit 3
fi fi
debug "Master current replication state:\n\tstate|sync_state\n\t$M_CUR_REPL_STATE_INFO" 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 ) 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" ] if [ "$M_CUR_STATE" != "streaming" ]
then 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 exit 2
fi fi
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" != "sync" ]
then 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 exit 2
fi fi
@ -350,15 +350,15 @@ then
M_CUR_XLOG="$( psql_master_get 'SELECT pg_current_xlog_location()' )" M_CUR_XLOG="$( psql_master_get 'SELECT pg_current_xlog_location()' )"
if [ ! -n "$M_CUR_XLOG" ] if [ ! -n "$M_CUR_XLOG" ]
then then
echo "UNKNOWN : Can't retreive current xlog from master server" echo "UNKNOWN: Can't retreive current xlog from master server"
exit 3 exit 3
fi fi
debug "Master current xlog : $M_CUR_XLOG" debug "Master current xlog: $M_CUR_XLOG"
# Master current xlog is the last receive xlog ? # Master current xlog is the last receive xlog ?
if [ "$M_CUR_XLOG" != "$LAST_XLOG_RECEIVE" ] if [ "$M_CUR_XLOG" != "$LAST_XLOG_RECEIVE" ]
then 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 exit 2
fi fi
debug "Master current xlog is the last receive xlog" debug "Master current xlog is the last receive xlog"
@ -372,19 +372,19 @@ then
debug "Replay delay is $REPLAY_DELAY second(s)" debug "Replay delay is $REPLAY_DELAY second(s)"
if [ $( echo "$REPLAY_DELAY >= $REPLAY_CRITICAL_DELAY"|bc -l ) -gt 0 ] if [ $( echo "$REPLAY_DELAY >= $REPLAY_CRITICAL_DELAY"|bc -l ) -gt 0 ]
then 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 exit 2
fi fi
if [ $( echo "$REPLAY_DELAY >= $REPLAY_WARNING_DELAY"|bc -l ) -gt 0 ] if [ $( echo "$REPLAY_DELAY >= $REPLAY_WARNING_DELAY"|bc -l ) -gt 0 ]
then 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 exit 1
fi fi
debug "Replay delay is not worrying" debug "Replay delay is not worrying"
fi fi
debug "Last receive xlog file is the last replay file" 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 exit 0
else else
debug "File recovery.conf not found. Master mode." debug "File recovery.conf not found. Master mode."
@ -392,7 +392,7 @@ else
# Check recovery mode # Check recovery mode
if [ $RECOVERY_MODE -eq 1 ] if [ $RECOVERY_MODE -eq 1 ]
then 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 exit 2
fi fi
debug "Postgres is not in recovery mode" debug "Postgres is not in recovery mode"
@ -409,7 +409,7 @@ else
) AS s1" ) ) AS s1" )
if [ ! -n "$STANDBY_CLIENTS" ] if [ ! -n "$STANDBY_CLIENTS" ]
then then
echo "WARNING : no stand-by client connected" echo "WARNING: no stand-by client connected"
exit 1 exit 1
fi fi
debug "Stand-by client(s):\n\t$( echo -e "$STANDBY_CLIENTS"|sed 's/\n/\n\t/' )" 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)" STANDBY_CLIENTS_TXT="$STANDBY_CLIENTS_TXT\n$NAME ($IP): $STATE/$SYNC_STATE (Location: sent='$SENT_LOCATION' / write='$WRITE_LOCATION', Lag: ${LAG}b)"
done 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 exit 0
fi fi