]> git.pld-linux.org Git - packages/postgresql.git/blobdiff - postgresql.init
- adapterized, remaining pl translations, BuildRequires: automake
[packages/postgresql.git] / postgresql.init
index 2031cd9bba9b5a3f4f756ed80eca79ddb5345254..75f7b6f233faa94e2a41ced26aed2521586f9fa1 100644 (file)
@@ -22,60 +22,144 @@ if [ -f /etc/sysconfig/postgresql ] ; then
         . /etc/sysconfig/postgresql
 else
         ALLOW_TCP_CONNECTIONS=no
-       POSTGRES_DATA_DIR=/var/state/psql
+       POSTGRES_DATA_DIR=/var/lib/psql
+       POSTGRES_LOG=/var/log/pgsql
 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
+# check if postmaster is realy alive
+if [ -f /var/lib/pgsql/postmaster.pid ]; then
+ if ps -p `head -1 /var/lib/pgsql/postmaster.pid` > /dev/null ; then
+        #ok. it's alive
+       echo > /dev/null;
+ else
+        # oh, it has crashed
+        rm -f  /var/lock/subsys/postgresql
+ fi
+else
+       # it's stoped. 
+       rm -f  /var/lock/subsys/postgresql
+fi
+
 
 # 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
+       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 ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
+                   # Check version of existing PGDATA
+                   if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; 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
+                       chmod 700 $POSTGRES_DATA_DIR
+                   fi
+                   TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
+                       initdb --pgdata=$POSTGRES_DATA_DIR \
+                       -L /usr/share/postgresql"
+               fi
+               
+               msg_starting PostgreSQL 
                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") " \
-                       &
-               sleep 2
-               if ps ax | grep -v grep | grep -q postmaster; then
-                       deltext;ok
+               PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
+                   $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
+               POSTMASTER_OPTIONS=" \
+                   $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
+                   $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
+                   $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
+
+               TMPDIR=/tmp su postgres -c "\
+                       $(echo "/usr/bin/pg_ctl start $PGSQL_CMDLINE -l $POSTGRES_LOG") \
+                       $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
+                       $(echo "2>&1 >/dev/null")";
+
+               out=`status postmaster`
+               if [ $? -eq 0 ]; then 
+                   deltext; ok
                else
-                       deltext;fail
+                   deltext; fail 
+                   exit 1      
                fi
-       else
-               echo "Postgresql already is running"
        fi
        touch /var/lock/subsys/postgresql
        ;;
   stop)
-       show Stopping postgresql service
-       killproc postmaster
-       sleep 2
+
+       if [ ! -f /var/lock/subsys/postgresql ]; then
+               msg_Not_Running PostgreSQL
+               exit 0  
+       fi
+       msg_stopping postgreSQL
+       busy
+       PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
+       TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
+       out=`status postmaster`
+       if [ $? -eq 0 ]; then
+               deltext; fail
+               echo -e "\n$out";
+               exit 1
+       else
+               deltext; ok
+       fi
        rm -f /var/run/postmaster.pid
        rm -f /var/lock/subsys/postgresql
        ;;
   status)
-       status postmaster
+       PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
+       TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
        ;;
-  restart|reload)
-       $0 stop
+  restart)
+       $0 stop
        $0 start
        ;;
+  reload)
+       if [ ! -f /var/lock/subsys/postgresql ]; then
+               msg_Not_Running PostgreSQL
+               exit 0  
+       fi
+       msg_reloading postgreSQL
+       busy
+
+       PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
+           $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
+       POSTMASTER_OPTIONS=" \
+           $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
+           $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
+           $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
+
+       TMPDIR=/tmp su postgres -c "\
+               $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
+               $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
+               $(echo "2>&1 >/dev/null")";
+
+       out=`status postmaster`
+       if [ $? -eq 0 ]; then
+               deltext; ok
+       else
+               deltext; fail
+               echo -e "\n$out";
+               exit 1
+       fi
+       ;;
   *)
-       echo "Usage: postgresql {start|stop|status|restart|reload}"
+       msg_Usage "$0 {start|stop|status|restart|reload}"
        exit 1
 esac
 
This page took 0.091419 seconds and 4 git commands to generate.