]> git.pld-linux.org Git - packages/postgresql.git/blobdiff - postgresql.init
- release++
[packages/postgresql.git] / postgresql.init
index 3424339bbf1b77f80d6a4714711a0b956012ccdb..4b21ef182b7e12de0c2c4be31ab6486e4e67754c 100644 (file)
@@ -1,45 +1,90 @@
-#! /bin/sh
+#!/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
-# 
+# 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.
+# Source function library
 . /etc/rc.d/init.d/functions
 
-# Get config.
+# Get network config
 . /etc/sysconfig/network
 
-# Check that networking is up.
-# Pretty much need it for postmaster.
-[ ${NETWORKING} = "no" ] && exit 0
-
-[ -f /usr/bin/postmaster ] || exit 0
+# Get service config
+if [ -f /etc/sysconfig/postgresql ] ; then
+        . /etc/sysconfig/postgresql
+else
+        ALLOW_TCP_CONNECTIONS=no
+       POSTGRES_DATA_DIR=/var/lib/psql
+fi
 
-[ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
-
-# This script is slightly unusual in that the name of the daemon (postmaster)
-# is not the same as the name of the subsystem (postgresql)
+# 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)
-       show Starting postgresql service
-       busy
-       su postgres -c '/usr/bin/postmaster -S -D/var/lib/pgsql'
-       sleep 1
-       pid=`pidof postmaster`
+       # 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
-       echo $pid > /var/run/postmaster.pid
-       deltext; ok
        ;;
   stop)
-       show Stopping postgresql service
+       msg_stopping postgresql
        killproc postmaster
        sleep 2
        rm -f /var/run/postmaster.pid
@@ -48,12 +93,12 @@ case "$1" in
   status)
        status postmaster
        ;;
-  restart)
+  restart|reload)
        $0 stop
        $0 start
        ;;
   *)
-       echo "Usage: postgresql {start|stop|status|restart}"
+       msg_Usage "$0 {start|stop|status|restart|reload}"
        exit 1
 esac
 
This page took 0.028451 seconds and 4 git commands to generate.