]> git.pld-linux.org Git - packages/postgresql.git/commitdiff
- create global subsys lock file if there is any postgresql instance
authorwrobell <wrobell@pld-linux.org>
Wed, 5 Feb 2003 11:05:24 +0000 (11:05 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
  running

Changed files:
    postgresql.init -> 1.46

postgresql.init

index 3abcf7bc5427d983c6e688c15f40c08b4db432e1..840cc27c5ee007b337423360476654369c9da337 100644 (file)
@@ -37,6 +37,21 @@ if is_no "${NETWORKING}"; then
        exit 1
 fi
 
+action="$1"
+
+# any db cluster as command line argument?
+if [ $# -gt 1 ]; then
+       shift
+       # perform action for specified clusters only
+       DB_CLUSTERS="$@"
+else
+       DB_CLUSTERS="$PG_DB_CLUSTERS"
+fi
+
+#
+# Useful functions.
+#
+
 #
 # check for postgresql status
 #
@@ -66,60 +81,63 @@ pgstatus() {
 # arguments:
 # $1 - db cluster
 #
-# sets variables:
-# PG_STARTED = 1 if instance has started up; please note, that function
-#              will not set to other value
-#
 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
-        PG_STARTED=1
-        deltext; ok
-    else
-        deltext; fail 
-    fi
+       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"
+#
+# check for running postgresql instances; if any instance is running then
+# create subsys lock file
+#
+pgsubsys() {
+       # check for every defined db cluster in sysconfig file
+       for pgdir in $PG_DB_CLUSTERS; do
+               pgstatus "$pgdir"
+               if [ "$PG_STATUS" = "running" ]; then
+                       touch /var/lock/subsys/postgresql
+                       return
+               fi
+       done
+       rm -f /var/lock/subsys/postgresql
+}
 
-# any db cluster as command line argument?
-if [ $# -gt 1 ]; then
-       shift
-       DB_CLUSTERS="$@"
-else
-    DB_CLUSTERS="$PG_DB_CLUSTERS"
-fi
+#
+# End of useful functions.
+#
 
 # See how we were called.
 # Every action is performed for all given (all configured by default)
 # db clusters.
 case "$action" in
        start)
-               PG_STARTED=0
                for pgdir in $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
+                               # 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
+                                       # pg_ctl has misinformed us about postgresql status;
+                                       # remove pid file and run postgresql
                                        msg_not_running "PostgreSQL $pgdir"
                                        rm -f $pgdir/postmaster.pid
-                    pgstart "$pgdir"
+                                       pgstart "$pgdir"
                                fi
                        else
-                pgstart "$pgdir"
+                               pgstart "$pgdir"
                        fi
                done
-        # one of instances has started, so create the lock
-        [ $PG_STARTED -eq 1 ] && touch /var/lock/subsys/postgresql
+               pgsubsys
        ;;
        stop)
                for pgdir in $DB_CLUSTERS; do
@@ -130,7 +148,7 @@ case "$action" in
                                msg_stopping "PostgreSQL $pgdir"
                                busy
 
-                # is postgresql really alive?
+                               # 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"
@@ -140,19 +158,20 @@ case "$action" in
                                                deltext; ok
                                        fi
                                else
-                    # postgresql is not really alive; pg_ctl misinformed us
-                    # about the status
+                                       # postgresql is not really alive; pg_ctl misinformed us
+                                       # about the status
                                        deltext; died
                                fi
 
                                rm -f $pgdir/postmaster.pid
                        fi
                done
+               pgsubsys
        ;;
        status)
                for pgdir in $DB_CLUSTERS; do
                        TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir status"
-               done
+               done
        ;;
        restart)
                $0 stop "$DB_CLUSTERS"
@@ -167,7 +186,7 @@ case "$action" in
                                msg_reloading "PostgreSQL $pgdir"
                                busy
 
-                # is postgresql really alive?
+                               # 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"
 
@@ -178,14 +197,15 @@ 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
+                                       # 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
                                        pgstart "$pgdir"
                                fi
                        fi
                done
+               pgsubsys
        ;;
        *)
                msg_usage "$0 {start|stop|status|restart|reload}"
This page took 0.133441 seconds and 4 git commands to generate.