]> granicus.if.org Git - postgresql/blobdiff - contrib/start-scripts/linux
Remove cvs keywords from all files.
[postgresql] / contrib / start-scripts / linux
index 19042d0e994ccc58068d9f3e4b5188828bbd35e2..4ad66917e6508aa507265962ab03e7a60ab14056 100644 (file)
@@ -24,7 +24,7 @@
 
 # Original author:  Ryan Kirkpatrick <pgsql@rkirkpat.net>
 
-# $PostgreSQL: pgsql/contrib/start-scripts/linux,v 1.6 2003/11/29 19:51:36 pgsql Exp $
+# contrib/start-scripts/linux
 
 ## EDIT FROM HERE
 
@@ -34,58 +34,73 @@ 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
 PGLOG="$PGDATA/serverlog"
 
-## STOP EDITING HERE
+# It's often a good idea to protect the postmaster from being killed by the
+# OOM killer (which will tend to preferentially kill the postmaster because
+# of the way it accounts for shared memory).  Setting the OOM_ADJ value to
+# -17 will disable OOM kill altogether.  If you enable this, you probably want
+# to compile PostgreSQL with "-DLINUX_OOM_ADJ=0", so that individual backends
+# can still be killed by the OOM killer.
+#OOM_ADJ=-17
 
-# Check for echo -n vs echo \c
-if echo '\c' | grep -s c >/dev/null 2>&1 ; then
-    ECHO_N="echo -n"
-    ECHO_C=""
-else
-    ECHO_N="echo"
-    ECHO_C='\c'
-fi
+## STOP EDITING HERE
 
 # 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.  (If you want the script to wait
+# until the server has started, you could use "pg_ctl start -w" here.
+# But without -w, pg_ctl adds no value.)
+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 ||
+{
+       echo "$DAEMON not found"
+       if [ "$1" = "stop" ]
+       then exit 0
+       else exit 5
+       fi
+}
+
 
 # Parse command line parameters.
 case $1 in
   start)
-       $ECHO_N "Starting PostgreSQL: "$ECHO_C
-       su - $PGUSER -c "$DAEMON start -D '$PGDATA' -s -l $PGLOG" 
+       echo -n "Starting PostgreSQL: "
+       test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
+       su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
        echo "ok"
        ;;
   stop)
        echo -n "Stopping PostgreSQL: "
-       su - $PGUSER -c "$DAEMON stop -D '$PGDATA' -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 -D '$PGDATA' -s -m fast -l $PGLOG"
+       su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
+       test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
+       su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
        echo "ok"
        ;;
   reload)
         echo -n "Reload PostgreSQL: "
-        su - $PGUSER -c "$DAEMON reload -D '$PGDATA' -s"
+        su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
         echo "ok"
         ;;
   status)
-       su - $PGUSER -c "$DAEMON status -D '$PGDATA'"
+       su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
        ;;
   *)
        # Print help