#!/bin/sh # # 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: /var/run/postmaster.pid # Source function library . /etc/rc.d/init.d/functions # Get network config . /etc/sysconfig/network # Get service config if [ -f /etc/sysconfig/postgresql ] ; then . /etc/sysconfig/postgresql else ALLOW_TCP_CONNECTIONS=no POSTGRES_DATA_DIR=/var/state/psql fi # Check that networking is up. if is_no "${NETWORKING}"; then msg_Network_Down Postgresql exit 1 fi # See how we were called. case "$1" in start) # Check if the service is already running? if [ ! -f /var/lock/subsys/postgresql ]; then # Sanity check [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432 STARTTEXT="Starting postgresql" # Check for the PGDATA structure if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -d $POSTGRES_DATA_DIR/base/template1 ]; then # Check version of existing PGDATA if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '6.5' ]; then STARTTEXT="$STARTTEXT [Old version. Need to Upgrade]" show "$STARTTEXT"; fail exit 1 fi else # Create sample database if [ ! -d $POSTGRES_DATA_DIR ]; then mkdir -p $POSTGRES_DATA_DIR chown postgres.postgres $POSTGRES_DATA_DIR fi show "Creating postgresql init database" busy su postgres -c "LD_LIBRARY_PATH=/usr/lib \ initdb --pgdata=$POSTGRES_DATA_DIR \ --pglib=/usr/lib/pgsql &>/tmp/initdb.pgsql" deltext; ok fi show "$STARTTEXT" busy su postgres -c "/usr/bin/postmaster \ $([ "$ALLOW_TCP_CONNECTIONS" = yes ] && echo "-i") \ $([ -n "$MAX_NUM_BACKENDS" ] && echo "-N $MAX_NUM_BACKENDS") \ $([ -n "POSTGRES_$DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \ -o \ $([ "$POSTGRES_QUIET" = yes ] && echo "-Q") \ $([ "$POSTGRES_DIABLE_FSYNC" = yes ] && echo "-F") 2> /dev/null &" sleep 2 if ps ax | grep -v grep | grep -q postmaster; then deltext; ok else deltext; fail fi else msg_Already_Running Postgresql fi touch /var/lock/subsys/postgresql ;; stop) msg_stopping postgresql killproc postmaster sleep 2 rm -f /var/run/postmaster.pid rm -f /var/lock/subsys/postgresql ;; status) status postmaster ;; restart|reload) $0 stop $0 start ;; *) msg_Usage "$0 {start|stop|status|restart|reload}" exit 1 esac exit 0