#!/bin/sh # # postgres - This script is used to start/stop # the postgreSQL listener process. # # Usage # # You can use this script manually, and/or you # can install this script into the runlevel system # by running "sh postgres.init.sh install" # # Credits # # Thomas Lockhart # modified from other startup files in the # RedHat Linux distribution # # Clark Evans # cleaned up, added comments, etc. # # modified for PostgreSQL book written by Tatsuo Ishii # # RedHat Stuff # # chkconfig: 345 85 15 # description: Starts and stops the PostgreSQL backend daemon\ # that handles all database requests. # processname: postmaster # pidfile: /var/run/postmaster.pid # # Config Variables # # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network PGACCOUNT="postgres" # # The non-root user account which will be used to run the # PostgreSQL executeable. For this script to work, the # shell for this account must be SH/BASH. # POSTGRES_HOME="/usr/local/pgsql" PGDATA="/usr/local/pgsql/data" POSTMASTER="/usr/local/pgsql/bin/postmaster" PG_CTL="/usr/local/pgsql/bin/pg_ctl" PGPORT="5432" PGLOG="/usr/local/pgsql/pgstartup.log" export PGPORT # # The executable program which is to be run, in this case # it is the listener, which waits for requests on the port # specified during configuration. # pidfile="/var/run/postmaster.pid" pidfile_make="ps -ef | grep -v grep | grep $POSTGRES_HOME | awk '{print \$2}' > $pidfile" pidfile_del="rm -f $pidfile" # # See how we were called. # case "$1" in start) # Start daemons. if [ -f /var/lock/subsys/postgresql ] ; then echo "PostgreSQL already started!" exit 1 fi echo -n "Starting PostgreSQL: " su - $PGACCOUNT -c "$POSTMASTER -p $PGPORT -D $PGDATA &" >> $PGLOG 2>&1 < /dev/null daemon $pidfile_make RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/postgresql ;; stop) # Stop daemons. if [ ! -f /var/lock/subsys/postgresql ] ; then echo "PostgreSQL already stopped!" exit 1 fi echo -n "Stopping PostgreSQL: " su - $PGACCOUNT -c "$PG_CTL stop -m f -D $PGDATA" > /dev/null 2>&1 < /dev/null daemon $pidfile_del RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/postgresql ;; status) status postgresql exit $? ;; restart) $0 stop sleep 1 $0 start ;; *) echo "Usage: $0 {start|stop|status|restart}" exit 1 esac exit 0