]> granicus.if.org Git - postgresql/blobdiff - contrib/start-scripts/linux
Adjust postmaster to recognize that a lockfile containing its parent's PID
[postgresql] / contrib / start-scripts / linux
index 9b0d0737f3657ab3ea869f20ea845923e2818cb7..e0174de571d580281e8b78e0ac0bfce4a9bb1995 100644 (file)
@@ -1,5 +1,8 @@
 #! /bin/sh
 
+# chkconfig: 2345 98 02
+# description: PostgreSQL RDBMS
+
 # This is an example of a start/stop script for SysV-style init, such
 # as is used on Linux systems.  You should edit some of the variables
 # and maybe the 'echo' commands.
@@ -12,7 +15,8 @@
 #   /etc/rc.d/rc3.d/S98postgresql
 #   /etc/rc.d/rc4.d/S98postgresql
 #   /etc/rc.d/rc5.d/S98postgresql
-# Or check out the chkconfig program, if you have it.
+# Or, if you have chkconfig, simply:
+# chkconfig --add postgresql
 #
 # Proper init scripts on Linux systems normally require setting lock
 # and pid files under /var/run as well as reacting to network
@@ -20,7 +24,7 @@
 
 # Original author:  Ryan Kirkpatrick <pgsql@rkirkpat.net>
 
-# $Header: /cvsroot/pgsql/contrib/start-scripts/linux,v 1.1 2001/02/08 19:53:33 petere Exp $
+# $PostgreSQL: pgsql/contrib/start-scripts/linux,v 1.7 2004/10/01 18:30:21 tgl Exp $
 
 ## EDIT FROM HERE
 
@@ -30,7 +34,7 @@ prefix=/usr/local/pgsql
 # Data directory
 PGDATA="/usr/local/pgsql/data"
 
-# Who to run pg_ctl as, should be "postgres".
+# Who to run the postmaster as, usually "postgres".  (NOT "root")
 PGUSER=postgres
 
 # Where to keep a log file
@@ -38,8 +42,6 @@ PGLOG="$PGDATA/serverlog"
 
 ## STOP EDITING HERE
 
-export PGDATA
-
 # Check for echo -n vs echo \c
 if echo '\c' | grep -s c >/dev/null 2>&1 ; then
     ECHO_N="echo -n"
@@ -52,37 +54,48 @@ fi
 # The path that is to be used for the script
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
-# What to use to start up the postmaster
-DAEMON="$prefix/bin/pg_ctl"
+# What to use to start up the postmaster (we do NOT use pg_ctl for this,
+# as it adds no value and can cause the postmaster to misrecognize a stale
+# lock file)
+DAEMON="$prefix/bin/postmaster"
+
+# What to use to shut down the postmaster
+PGCTL="$prefix/bin/pg_ctl"
 
 set -e
 
-# Only start if we can find pg_ctl.
-test -f $DAEMON || exit 0
+# Only start if we can find the postmaster.
+test -x $DAEMON || exit 0
 
 # Parse command line parameters.
 case $1 in
   start)
        $ECHO_N "Starting PostgreSQL: "$ECHO_C
-       su - $PGUSER -c "$DAEMON start -s -l $PGLOG" 
+       su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
        echo "ok"
        ;;
   stop)
        echo -n "Stopping PostgreSQL: "
-       su - $PGUSER -c "$DAEMON stop -s -m fast"
+       su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
        echo "ok"
        ;;
   restart)
        echo -n "Restarting PostgreSQL: "
-       su - $PGUSER -c "$DAEMON restart -s -m fast"
+       su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
+       su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
        echo "ok"
        ;;
+  reload)
+        echo -n "Reload PostgreSQL: "
+        su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
+        echo "ok"
+        ;;
   status)
-       su - $PGUSER -c "$DAEMON status"
+       su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
        ;;
   *)
        # Print help
-       echo "Usage: $0 {start|stop|restart|status}" 1>&2
+       echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
        exit 1
        ;;
 esac