]> git.pld-linux.org Git - packages/postgresql.git/blobdiff - postgresql.init
rebuild with perl 5.34.0
[packages/postgresql.git] / postgresql.init
index 00f86ff095faeaec00f126b18c59482388b37462..647f2ec4328af6cab69cf80b305ae8a7c25863b1 100644 (file)
@@ -6,21 +6,25 @@
 # chkconfig:   345 84 25
 #
 # description: Starts and stops the PostgreSQL backend daemon that handles \
-#                              all database requests.
+#              all database requests.
 #
 # processname: postmaster
 
+cd /
+
 # Source function library
 . /etc/rc.d/init.d/functions
 
 # Get network config
 . /etc/sysconfig/network
 
+PG_INIT_LOCALE=C
+
 # Get service config
 if [ -f /etc/sysconfig/postgresql ]; then
        . /etc/sysconfig/postgresql
 else
-       nls "Error: /etc/sysconfig/postgresql not found"
+       nls "Error: %s not found" /etc/sysconfig/postgresql
        nls " PostgreSQL can't be run."
        exit 1
 fi
@@ -69,13 +73,15 @@ fi
 pgstatus() {
        PG_STATUS="unknown"
        PG_PID="unknown"
-       status=`/usr/bin/pg_ctl -D $1 status`
+       output=$(LC_ALL=C TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $1 status")
+       status=$?
 
-       if echo "$status" | grep -q 'pg_ctl: postmaster or postgres is not running'; then
+       if [ $status -eq 3 ]; then
                PG_STATUS="not running"
-       elif echo "$status" | grep -q 'pg_ctl: postmaster is running'; then
+       elif [ $status -eq 0 ]; then
                PG_STATUS="running"
-               PG_PID=`echo "$status" | sed 's/^pg_ctl:.*pid: \([0-9]\+\).*/\1/' | head -1`
+       # or maybe grab it from postmaster.pid file?
+               PG_PID=$(echo "$output" | awk '/PID: / { match($0, "PID: [0-9]+"); print substr($0,RSTART+5,RLENGTH-5) }')
        fi
 }
 
@@ -86,16 +92,9 @@ pgstatus() {
 # $1 - db cluster
 #
 pgstart() {
+       is_no "$RC_LOGGING" && fork=--fork
        msg_starting "PostgreSQL $1"
-       busy
-       TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -w -D $1 start 2>&1 >/dev/null"
-       sleep 1
-       pgstatus "$1"
-       if [ "$PG_STATUS" != "unknown" -a "$PG_PID" != "unknown" ]; then
-               ok
-       else
-               fail 
-       fi
+       daemon $fork --user postgres /usr/bin/pg_ctl -s -w -D $1 start
 }
 
 #
@@ -118,18 +117,13 @@ pgsubsys() {
 # 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)
+start() {
        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
-                       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;
@@ -143,8 +137,9 @@ case "$action" in
                fi
        done
        pgsubsys
-       ;;
-  stop)
+}
+
+stop() {
        for pgdir in $DB_CLUSTERS; do
                pgstatus "$pgdir"
                if [ "$PG_STATUS" = "not running" ]; then
@@ -152,8 +147,8 @@ case "$action" in
                else
                        msg_stopping "PostgreSQL $pgdir"
                        busy
-                               # is postgresql really alive?
-                       if ps ax | grep -v grep | grep -q "$PG_PID"; then
+                       # is postgresql really alive?
+                       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
@@ -170,33 +165,67 @@ case "$action" in
                fi
        done
        pgsubsys
+}
+
+
+RETVAL=0
+# See how we were called.
+# Every action is performed for all given (all configured by default)
+# db clusters.
+case "$action" in
+  start)
+       start
+       ;;
+  stop)
+       stop
        ;;
   status)
        for pgdir in $DB_CLUSTERS; do
-       TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl -D $pgdir status"
-               done
+               pgstatus "$pgdir"
+               if [ "$PG_STATUS" = "running" ]; then
+                       show "PostgreSQL cluster %s, PID %s" "$pgdir" "$PG_PID"
+                       progress "$PG_STATUS"
+               else
+                       show "PostgreSQL cluster %s" "$pgdir"
+                       progress "$PG_STATUS" "$CFAIL"
+               fi
+               echo
+       done
        ;;
   restart)
-       $0 stop "$DB_CLUSTERS"
-       $0 start "$DB_CLUSTERS"
+       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
@@ -219,8 +248,8 @@ case "$action" in
                        echo $(nls "Initializing cluster %s" "$pgdir")
                        mkdir -p $pgdir
                        chmod 700 $pgdir
-                       chown postgres.postgres $pgdir
-                       TMPDIR=/tmp su - postgres -s /bin/sh -c "initdb -E UNICODE -D $pgdir"
+                       chown postgres:postgres $pgdir
+                       LC_ALL=$PG_INIT_LOCALE TMPDIR=/tmp su postgres -s /bin/sh -c "initdb -E UNICODE --data-checksums -D $pgdir"
                fi
        done
        echo $(nls "REMEMBER to setup password for user \"postgres\"")'!'
@@ -230,4 +259,4 @@ case "$action" in
        exit 3
 esac
 
-exit 0
+exit $RETVAL
This page took 0.069461 seconds and 4 git commands to generate.