#! /bin/bash # postgresql This is the init script for starting up the PostgreSQL # server # chkconfig: 345 85 15 # description: Starts and stops the PostgreSQL backend daemon that handles \ # all database requests. # processname: postmaster # pidfile: /home/cheshire/cheshire3/install/share/postgresql/data/postmaster.pid # # Source function library. . /etc/rc.d/init.d/functions # Get config. . /etc/sysconfig/network # Check that networking is up. # Pretty much need it for postmaster. [ ${NETWORKING} = "no" ] && exit 0 [ -f /home/cheshire/cheshire3/install/bin/postmaster ] || exit 0 # This script is slightly unusual in that the name of the daemon (postmaster) # is not the same as the name of the subsystem (postgresql) C3HOME='/home/cheshire/cheshire3' export LD_LIBRARY_PATH=$C3HOME/install/lib:$LD_LIBRARY_PATH export LDFLAGS=-L$C3HOME/install/lib export CPPFLAGS=-I$C3HOME/install/include export PATH=$C3HOME/install/bin:$PATH black="\033[0m" red="\033[0;31m" green="\033[0;32m" start() { echo -n "Checking postgresql installation: " # Check for the PGDATA structure if [ -f $C3HOME/install/share/postgresql/data/PG_VERSION ] && [ -d $C3HOME/install/share/postgresql/data/base ] then echo version `cat $C3HOME/install/share/postgresql/data/PG_VERSION` # No existing PGDATA! Initdb it. else echo "no database files found." if [ ! -d $C3HOME/install/share/postgresql ] then mkdir -p $C3HOME/install/share/postgresql/data chown cheshire:cheshire $C3HOME/install/share/postgresql/data fi su -l cheshire -c 'initdb -D '$C3HOME'/install/share/postgresql/data' fi # Check for postmaster already running... pidfile=$C3HOME/install/share/postgresql/data/postmaster.pid if [ -f $pidfile ] then echo "Postmaster already running...: [" `pidof postmaster` "]" return 0 else #all systems go -- remove any stale lock files rm -f /tmp/.s.PGSQL.* > /dev/null echo -n "Starting postgresql service: " su -l cheshire -c 'postmaster -D '$C3HOME'/install/share/postgresql/data >'$C3HOME'/install/logs/postgresql.log 2>&1 &' sleep 1 pid=`/sbin/pidof postmaster` if [[ -n $pid ]] then touch /var/lock/subsys/postgresql && echo $pid > $pidfile && chown cheshire.cheshire $pidfile echo -n [ && echo -en $green && echo -n " OK " && echo -en $black && echo "]" - $pid return 0 else echo -n [ && echo -en $red && echo -n "FAILED" && echo -en $black && echo "]" return 1 fi fi } stop() { echo -n "Stopping postgresql service: " killproc postmaster sleep 2 rm -f $C3HOME/install/share/postgresql/data/postmaster.pid rm -f /var/lock/subsys/postgresql echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status postmaster ;; restart) stop start ;; *) echo "Usage: postgresql {start|stop|status|restart}" exit 1 ;; esac exit 0