]> git.pld-linux.org Git - packages/postgresql.git/commitdiff
- do not use $0 start recursively - introduced pgstart function to simplify
authorwrobell <wrobell@pld-linux.org>
Thu, 9 Jan 2003 00:22:43 +0000 (00:22 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
  the script
- more comments about script code

Changed files:
    postgresql.init -> 1.43

postgresql.init

index 4606a6bb534f0bf17991b8c07a71c6be4c8c494c..8da6977b694def2ab4181681c42cbe761df58ffe 100644 (file)
@@ -31,6 +31,16 @@ if is_no "${NETWORKING}"; then
        exit 1
 fi
 
+#
+# check for postgresql status
+#
+# arguments:
+# $1 - db cluster
+#
+# sets variables:
+# PG_STATUS = running | not running
+# PG_PID    = pid of postmaster process
+#
 pgstatus () {
        PG_STATUS="unknown"
        PG_PID="unknown"
@@ -44,6 +54,24 @@ pgstatus () {
        fi
 }
 
+#
+# start postgresql and display appropriate messages
+# arguments:
+# $1 - db cluster
+#
+pgstart() {
+    msg_starting "PostgreSQL $1"
+    busy
+    TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $1 start 2>&1 >/dev/null"
+
+    pgstatus "$1"
+    if [ "$PG_STATUS" != "unknown" -a "$PG_PID" != "unknown" ]; then
+        deltext; ok
+    else
+        deltext; fail 
+    fi
+}
+
 action="$1"
 
 # any db cluster as command line argument?
@@ -53,29 +81,25 @@ if [ $# -gt 1 ]; then
 fi
 
 # See how we were called.
+# Every action is performed for all given (default all configured) db clusters.
 case "$action" in
        start)
                for pgdir in $POSTGRES_DB_CLUSTERS; do
                        pgstatus "$pgdir"
                        if [ "$PG_STATUS" = "running" ]; then
+                # pg_ctl status can misinform us about postgresql status
+                # so let's check if postmaster is really alive
                                if ps ax | grep -v grep | grep -q "$PG_PID"; then
                                        msg_already_running "PostgreSQL $pgdir"
                                else
+                    # pg_ctl has misinformed us about postgresql status;
+                    # remove pid file and run postgresql
                                        msg_not_running "PostgreSQL $pgdir"
                                        rm -f $pgdir/postmaster.pid
-                                       $0 start "$pgdir"
+                    pgstart "$pgdir"
                                fi
                        else
-                               msg_starting "PostgreSQL $pgdir"
-                               busy
-                               TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $pgdir start 2>&1 >/dev/null"
-                               
-                               pgstatus "$pgdir"
-                               if [ "$PG_STATUS" != "unknown" -a "$PG_PID" != "unknown" ]; then
-                                       deltext; ok
-                               else
-                                       deltext; fail 
-                               fi
+                pgstart "$pgdir"
                        fi
                done
        ;;
@@ -88,6 +112,7 @@ case "$action" in
                                msg_stopping "PostgreSQL $pgdir"
                                busy
 
+                # is postgresql really alive?
                                if ps ax | grep -v grep | grep -q "$PG_PID"; then
                                        TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $pgdir stop -m fast 2>&1 >/dev/null"
                                        pgstatus "$pgdir"
@@ -97,6 +122,8 @@ case "$action" in
                                                deltext; ok
                                        fi
                                else
+                    # postgresql is not really alive; pg_ctl misinformed us
+                    # about the status
                                        deltext; died
                                fi
 
@@ -122,6 +149,7 @@ case "$action" in
                                msg_reloading "PostgreSQL $pgdir"
                                busy
 
+                # is postgresql really alive?
                                if ps ax | grep -v grep | grep -q "$PG_PID"; then
                                        TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir restart 2>&1 >/dev/null"
 
@@ -132,9 +160,11 @@ case "$action" in
                                                deltext; fail
                                        fi
                                else
+                    # postgresql died and pg_ctl has misinformed us about
+                    # the status; remove pid file and start it again
                                        deltext; died
                                        rm -f $pgdir/postmaster.pid
-                                       $0 start
+                                       pgstart "$pgdir"
                                fi
                        fi
                done
This page took 0.050362 seconds and 4 git commands to generate.