#!/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/lib/psql POSTGRES_LOG=/var/log/pgsql 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 msg_Already_Running PostgreSQL else # Sanity check [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432 # 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` != '7.0' ]; then show "Databases created under incompatibile version. Migrate them first."; 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 su postgres -c "LD_LIBRARY_PATH=/usr/lib \ initdb --pgdata=$POSTGRES_DATA_DIR \ --pglib=/usr/lib/pgsql" fi msg_starting PostgreSQL busy PGSQL_CMDLINE="$([ "$ALLOW_TCP_CONNECTIONS" = yes ] && echo "-i") \ $([ -n "$MAX_NUM_BACKENDS" ] && echo "-N $MAX_NUM_BACKENDS") \ $([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \ $([ "$POSTGRES_QUIET". = yes. ] && echo '-o -Q') \ $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-o -F')"; su postgres -c "/usr/bin/postmaster $PGSQL_CMDLINE >>$POSTGRES_LOG 2>&1 &" out=`status postmaster` if [ $? -eq 0 ]; then deltext; ok else deltext; fail exit 1 fi fi touch /var/lock/subsys/postgresql ;; stop) if [ ! -f /var/lock/subsys/postgresql ]; then msg_Not_Running PostgreSQL exit 0 fi msg_stopping postgreSQL killproc postmaster out=`status postmaster` if [ $? -eq 0 ]; then deltext; fail echo -e "\n$out"; exit 1 fi 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