]> git.pld-linux.org Git - packages/postgresql.git/blobdiff - postgresql.init
- up to 9.1.4
[packages/postgresql.git] / postgresql.init
index 34b2d2a6290d27d70742e187a29f0d015e3eb7c5..1a5f91bdc3a94e7a507c69349c4f041b73930e6f 100644 (file)
@@ -18,6 +18,8 @@ cd /
 # Get network config
 . /etc/sysconfig/network
 
+PG_INIT_LOCALE=C
+
 # Get service config
 if [ -f /etc/sysconfig/postgresql ]; then
        . /etc/sysconfig/postgresql
@@ -79,7 +81,7 @@ pgstatus() {
        elif [ $status -eq 0 ]; then
                PG_STATUS="running"
         # or maybe grab it from postmaster.pid file?
-               PG_PID=`echo "$output" | sed 's/^pg_ctl:.*PID: \([0-9]\+\).*/\1/' | head -n 1`
+               PG_PID=$(echo "$output" | awk '/PID: / { match($0, "PID: [0-9]+"); print substr($0,RSTART+5,RLENGTH-5) }')
        fi
 }
 
@@ -90,8 +92,9 @@ pgstatus() {
 # $1 - db cluster
 #
 pgstart() {
+       is_no "$RC_LOGGING" && fork=--fork
        msg_starting "PostgreSQL $1"
-       daemon --user postgres /usr/bin/pg_ctl -s -w -D $1 start
+       daemon $fork --user postgres /usr/bin/pg_ctl -s -w -D $1 start
 }
 
 #
@@ -120,7 +123,7 @@ start() {
                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
+                       if ps -p "$PG_PID" >/dev/null; then
                                msg_already_running "PostgreSQL $pgdir"
                        else
                                # pg_ctl has misinformed us about postgresql status;
@@ -145,7 +148,7 @@ stop() {
                        msg_stopping "PostgreSQL $pgdir"
                        busy
                        # is postgresql really alive?
-                       if ps ax | grep -v grep | grep -q "$PG_PID"; then
+                       if ps -p "$PG_PID" >/dev/null; then
                                TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $pgdir stop -m fast 2>&1 >/dev/null"
                                pgstatus "$pgdir"
                                if [ "$PG_STATUS" != "not running" ]; then
@@ -164,6 +167,10 @@ stop() {
        pgsubsys
 }
 
+
+upstart_controlled --except status init
+
+RETVAL=0
 # See how we were called.
 # Every action is performed for all given (all configured by default)
 # db clusters.
@@ -191,23 +198,36 @@ case "$action" in
        stop
        start
        ;;
-  reload|force-reload)
+  reload|force-reload|try-restart)
+       if [ "$action" = "reload" ]; then
+               # "reload" must not restart service - so let it reload only what's possible
+               pgctlact="reload"
+       else
+               pgctlact="restart"
+       fi
        for pgdir in $DB_CLUSTERS; do
                pgstatus "$pgdir"
                if [ "$PG_STATUS" = "not running" ]; then
                        msg_not_running "PostgreSQL $pgdir"
+                       if [ "$action" != "try-restart" ]; then
+                               RETVAL=7
+                       fi
                else
                        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"
+                       if ps -p "$PG_PID" >/dev/null; then
+                               TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir $pgctlact 2>&1 >/dev/null"
                                        pgstatus "$pgdir"
                                if [ "$PG_STATUS" = "running" ]; then
                                        ok
                                else
                                        fail
                                fi
+                       elif [ "$action" != "try-restart" ]; then
+                               # postgresql died and pg_ctl has misinformed us about
+                               # the status - i.e. service is actually not running
+                               RETVAL=7
                        else
                                # postgresql died and pg_ctl has misinformed us about
                                # the status; remove pid file and start it again
@@ -231,7 +251,7 @@ case "$action" in
                        mkdir -p $pgdir
                        chmod 700 $pgdir
                        chown postgres:postgres $pgdir
-                       TMPDIR=/tmp su postgres -s /bin/sh -c "initdb -E UNICODE -D $pgdir"
+                       LC_ALL=$PG_INIT_LOCALE TMPDIR=/tmp su postgres -s /bin/sh -c "initdb -E UNICODE -D $pgdir"
                fi
        done
        echo $(nls "REMEMBER to setup password for user \"postgres\"")'!'
@@ -241,4 +261,4 @@ case "$action" in
        exit 3
 esac
 
-exit 0
+exit $RETVAL
This page took 0.043206 seconds and 4 git commands to generate.