# processname: postmaster
# pidfile: /var/run/postmaster.pid
-
# Source function library
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
# Get service config
-[ -f /etc/sysconfig/postgresql ] && . /etc/sysconfig/postgresql
+if [ -f /etc/sysconfig/postgresql ] ; then
+ . /etc/sysconfig/postgresql
+else
+ ALLOW_TCP_CONNECTIONS=no
+ POSTGRES_DATA_DIR=/var/lib/psql
+fi
# Check that networking is up.
-if [ "${NETWORKING}" = "no" ]; then
- echo "WARNING: Networking is down. Postgresql service can't be runed."
+if is_no "${NETWORKING}"; then
+ msg_Network_Down Postgresql
exit 1
fi
-# Sanity check
-[ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
-
-
# See how we were called.
case "$1" in
start)
# Check if the service is already running?
if [ ! -f /var/lock/subsys/postgresql ]; then
- show Starting postgresql
+
+ # 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
- touch /var/lock/subsys/postgresql
- deltext
- ok
+ 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
- echo "Postgresql already is running"
+ msg_Already_Running Postgresql
fi
touch /var/lock/subsys/postgresql
;;
stop)
- show Stopping postgresql service
+ msg_stopping postgresql
killproc postmaster
sleep 2
rm -f /var/run/postmaster.pid
$0 start
;;
*)
- echo "Usage: postgresql {start|stop|status|restart|reload}"
+ msg_Usage "$0 {start|stop|status|restart|reload}"
exit 1
esac