+

viewgit/inc/functions.php:74 Function create_function() is deprecated [8192]

Manage options

Benjamin Renard [2015-04-27 14:24:21]
Manage options
Filename
check_pg_streaming_replication
diff --git a/check_pg_streaming_replication b/check_pg_streaming_replication
index baaa1cd..78e1a8e 100755
--- a/check_pg_streaming_replication
+++ b/check_pg_streaming_replication
@@ -19,11 +19,78 @@
 PG_USER=postgres
 PSQL_BIN=/usr/bin/psql
 PG_MAIN=/var/lib/postgresql/9.1/main
-RECOVERY_CONF=$PG_MAIN/recovery.conf
+if [ -f /etc/redhat-release ]
+then
+	PG_MAIN=/var/lib/pgsql/9.1/data
+fi
+RECOVERY_CONF_FILENAME=recovery.conf
+RECOVERY_CONF=""
 PG_DEFAULT_PORT=5432

 DEBUG=0
-[ "$1" == "-d" ] && DEBUG=1
+
+function usage () {
+	cat << EOF
+Usage : $0 [-d] [-h] [options]
+	-u pg_user		Specify Postgres user (Default : $PG_USER)
+	-b psql_bin		Specify psql binary path (Default : $PSQL_BIN)
+	-m pg_main		Specify Postgres main directory path
+				(Default : $PG_MAIN)
+	-r recovery_conf	Specify Postgres recovery configuration file path
+				(Default : $PG_MAIN/$RECOVERY_CONF_FILENAME)
+	-p pg_port		Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT)
+	-d			Debug mode
+	-h 			Show this message
+EOF
+	exit 0
+}
+
+while getopts "hu:b:m:r:p:d" OPTION
+do
+	case $OPTION in
+		u)
+			PG_USER=$OPTARG
+		;;
+		b)
+			PSQL_BIN=$OPTARG
+		;;
+		m)
+			PG_MAIN=$OPTARG
+		;;
+		r)
+			RECOVERY_CONF=$OPTARG
+		;;
+		p)
+			PG_DEFAULT_PORT=$OPTARG
+		;;
+		d)
+			DEBUG=1
+		;;
+		h)
+			usage
+		;;
+		\?)
+			echo -n "Unkown option"
+			usage
+	esac
+done
+
+# Check PG_USER
+[ -z "$PG_USER" ] && echo "UNKNOWN : Postgres user not specify" && exit 3
+id "$PG_USER" > /dev/null 2>&1
+[ $? -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
+
+# Check PG_MAIN
+[ ! -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

 function psql_get () {
 	echo "$1"|su - $PG_USER -c "$PSQL_BIN -t -P format=unaligned"
@@ -36,6 +103,13 @@ function debug() {
 	fi
 }

+debug "Running options :
+PG_USER = $PG_USER
+PSQL_BIN = $PSQL_BIN
+PG_MAIN = $PG_MAIN
+RECOVERY_CONF = $RECOVERY_CONF
+PG_DEFAULT_PORT = $PG_DEFAULT_PORT"
+
 # Postgres is running ?
 if [ $DEBUG -eq 0 ]
 then
ViewGit