Benjamin Renard commited on 2015-04-27 14:24:21
Showing 1 changed files, with 76 additions and 2 deletions.
... | ... |
@@ -19,11 +19,78 @@ |
19 | 19 |
PG_USER=postgres |
20 | 20 |
PSQL_BIN=/usr/bin/psql |
21 | 21 |
PG_MAIN=/var/lib/postgresql/9.1/main |
22 |
-RECOVERY_CONF=$PG_MAIN/recovery.conf |
|
22 |
+if [ -f /etc/redhat-release ] |
|
23 |
+then |
|
24 |
+ PG_MAIN=/var/lib/pgsql/9.1/data |
|
25 |
+fi |
|
26 |
+RECOVERY_CONF_FILENAME=recovery.conf |
|
27 |
+RECOVERY_CONF="" |
|
23 | 28 |
PG_DEFAULT_PORT=5432 |
24 | 29 |
|
25 | 30 |
DEBUG=0 |
26 |
-[ "$1" == "-d" ] && DEBUG=1 |
|
31 |
+ |
|
32 |
+function usage () { |
|
33 |
+ cat << EOF |
|
34 |
+Usage : $0 [-d] [-h] [options] |
|
35 |
+ -u pg_user Specify Postgres user (Default : $PG_USER) |
|
36 |
+ -b psql_bin Specify psql binary path (Default : $PSQL_BIN) |
|
37 |
+ -m pg_main Specify Postgres main directory path |
|
38 |
+ (Default : $PG_MAIN) |
|
39 |
+ -r recovery_conf Specify Postgres recovery configuration file path |
|
40 |
+ (Default : $PG_MAIN/$RECOVERY_CONF_FILENAME) |
|
41 |
+ -p pg_port Specify default Postgres master TCP port (Default : $PG_DEFAULT_PORT) |
|
42 |
+ -d Debug mode |
|
43 |
+ -h Show this message |
|
44 |
+EOF |
|
45 |
+ exit 0 |
|
46 |
+} |
|
47 |
+ |
|
48 |
+while getopts "hu:b:m:r:p:d" OPTION |
|
49 |
+do |
|
50 |
+ case $OPTION in |
|
51 |
+ u) |
|
52 |
+ PG_USER=$OPTARG |
|
53 |
+ ;; |
|
54 |
+ b) |
|
55 |
+ PSQL_BIN=$OPTARG |
|
56 |
+ ;; |
|
57 |
+ m) |
|
58 |
+ PG_MAIN=$OPTARG |
|
59 |
+ ;; |
|
60 |
+ r) |
|
61 |
+ RECOVERY_CONF=$OPTARG |
|
62 |
+ ;; |
|
63 |
+ p) |
|
64 |
+ PG_DEFAULT_PORT=$OPTARG |
|
65 |
+ ;; |
|
66 |
+ d) |
|
67 |
+ DEBUG=1 |
|
68 |
+ ;; |
|
69 |
+ h) |
|
70 |
+ usage |
|
71 |
+ ;; |
|
72 |
+ \?) |
|
73 |
+ echo -n "Unkown option" |
|
74 |
+ usage |
|
75 |
+ esac |
|
76 |
+done |
|
77 |
+ |
|
78 |
+# Check PG_USER |
|
79 |
+[ -z "$PG_USER" ] && echo "UNKNOWN : Postgres user not specify" && exit 3 |
|
80 |
+id "$PG_USER" > /dev/null 2>&1 |
|
81 |
+[ $? -ne 0 ] && echo "UNKNOWN : Invalid Postgres user ($PG_USER)" && exit 3 |
|
82 |
+ |
|
83 |
+# Check PSQL_BIN |
|
84 |
+[ ! -x "$PSQL_BIN" ] && echo "UNKNOWN : Invalid psql bin path ($PSQL_BIN)" && exit 3 |
|
85 |
+ |
|
86 |
+# Check PG_MAIN |
|
87 |
+[ ! -d "$PG_MAIN/" ] && echo "UNKNOWN : Invalid Postgres main directory path ($PG_MAIN)" && exit 3 |
|
88 |
+ |
|
89 |
+# Check RECOVERY_CONF |
|
90 |
+[ -z "$RECOVERY_CONF" ] && RECOVERY_CONF="$PG_MAIN/$RECOVERY_CONF_FILENAME" |
|
91 |
+ |
|
92 |
+# Check PG_DEFAULT_PORT |
|
93 |
+[ $( echo "$PG_DEFAULT_PORT"|grep -c -E '^[0-9]*$' ) -ne 1 ] && "UNKNOWN : Postgres default master TCP port must be an integer." && exit 3 |
|
27 | 94 |
|
28 | 95 |
function psql_get () { |
29 | 96 |
echo "$1"|su - $PG_USER -c "$PSQL_BIN -t -P format=unaligned" |
... | ... |
@@ -36,6 +103,13 @@ function debug() { |
36 | 103 |
fi |
37 | 104 |
} |
38 | 105 |
|
106 |
+debug "Running options : |
|
107 |
+PG_USER = $PG_USER |
|
108 |
+PSQL_BIN = $PSQL_BIN |
|
109 |
+PG_MAIN = $PG_MAIN |
|
110 |
+RECOVERY_CONF = $RECOVERY_CONF |
|
111 |
+PG_DEFAULT_PORT = $PG_DEFAULT_PORT" |
|
112 |
+ |
|
39 | 113 |
# Postgres is running ? |
40 | 114 |
if [ $DEBUG -eq 0 ] |
41 | 115 |
then |
42 | 116 |