Allow logging of output to syslog or /tmp/postgres.log.
authorThomas G. Lockhart
Sat, 6 Dec 1997 03:02:34 +0000 (03:02 +0000)
committerThomas G. Lockhart
Sat, 6 Dec 1997 03:02:34 +0000 (03:02 +0000)
Put all configurable parameters near top of file.
Remove explicit path to postmaster executable.
More comments.

contrib/linux/postgres.init

index c6243df06503e0e6c295267e08906193b18d85a9..b8857796962255d847c2e9c9c2946e0085def7fd 100755 (executable)
@@ -1,20 +1,25 @@
-#! /bin/sh
+#!/bin/sh
 #
 # postgres.init Start postgres back end system.
 #
-# Author:       Thomas Lockhart <[email protected]>
-#               based on news startup by David Myers
+# Author:       Thomas Lockhart <[email protected]>
+#               modified from other startup files in the RedHat Linux distribution
 #
-# Written for RedHat Linux but should apply to other Linux distributions.
-#
-# To be installed as /etc/rc.d/init.d/postgres.init
-# Softlink into rc5.d to bring up with multiuser and networking:
-#   cd /etc/rc.d/rc5.d; ln -s ../init.d/postgres.init S98postgres
-#
-# Assumptions:
-# - the postgres user is named "postgres"
-# - the postgres user is running csh/tcsh
+# This version can log backend output through syslog using the local5 facility.
+# To enable this, edit /etc/syslog.conf to include a line similar to:
+#   local5.*  /var/log/postgres
+# and then set USE_SYSLOG to "yes" below
 #
+#PGBIN="/opt/postgres/current/bin" # not used
+PGACCOUNT="postgres"       # the postgres account (you called it something else?)
+POSTMASTER="postmaster"        # this probably won't change
+
+USE_SYSLOG="yes"       # "yes" to enable syslog, "no" to go to /tmp/postgres.log
+FACILITY="local5"      # can assign local0-local7 as the facility for logging
+PGLOGFILE="/tmp/postgres.log"  # only used if syslog is disabled
+
+PGOPTS="-B 256"
+#PGOPTS="-i -B 256"    # -i to enable TCP/IP rather than Unix socket
 
 # Source function library.
 . /etc/rc.d/init.d/functions
@@ -29,36 +34,41 @@ then
    exit 0
 fi
 
-[ -f /opt/postgres/current/bin/postmaster ] || exit 0
+#[ -f ${PGBIN}/${POSTMASTER} ] || exit 0
 
 # See how we were called.
 case "$1" in
   start)
-   echo -n "Starting postgres service: "
-# force full login to get path names and environment variables
-# postgres runs tcsh so use proper syntax in redirection
-# change this line if the postgres superuser account is not "postgres"
-# change this line if another shell syntax is necessary
-#  su - postgres -c 'postmaster -S' > /dev/null&
-   su - postgres -c 'postmaster >>&! /tmp/postmaster.log&' > /dev/null&
+   if [ -f ${PGLOGFILE} ]
+   then
+       mv ${PGLOGFILE} ${PGLOGFILE}.old
+   fi
+   echo -n "Starting postgres: "
+# force full login to get path names
+# my postgres runs tcsh so use proper syntax in redirection...
+   if [ ${USE_SYSLOG} = "yes" ]; then
+       su - ${PGACCOUNT} -c "(${POSTMASTER} ${PGOPTS} |& logger -p ${FACILITY}.notice) &" > /dev/null&
+   else
+       su - ${PGACCOUNT} -c "${POSTMASTER} ${PGOPTS} >>&! ${PGLOGFILE} &" > /dev/null&
+   fi
    sleep 5
-   pid=`pidof postmaster`
-   echo -n "postmaster [$pid]"
-#  touch /var/lock/subsys/postmaster
+   pid=`pidof ${POSTMASTER}`
+   echo -n "${POSTMASTER} [$pid]"
+#  touch /var/lock/subsys/${POSTMASTER}
    echo
    ;;
   stop)
-   echo -n "Stopping postgres service: "
-   pid=`pidof postmaster`
+   echo -n "Stopping postgres: "
+   pid=`pidof ${POSTMASTER}`
    if [ "$pid" != "" ] ; then
-       echo -n "postmaster [$pid]"
+       echo -n "${POSTMASTER} [$pid]"
        kill -TERM $pid
        sleep 1
    fi
    echo
    ;;
   *)
-   echo "Usage: postgres.init {start|stop}"
+   echo "Usage: $0 {start|stop}"
    exit 1
 esac