]> git.pld-linux.org Git - packages/postgresql.git/blobdiff - postgresql.init
- more things, reminder about password etc
[packages/postgresql.git] / postgresql.init
index 6ebbe2f9959eff085649821889d4028fdf92d5ac..11343041dca1609288816b5b0fee56e645135f87 100644 (file)
@@ -3,13 +3,13 @@
 # postgresql   This is the init script for starting up the PostgreSQL
 #              server
 #
-# chkconfig:   345 85 15
+# chkconfig:   345 84 25
 #
 # description: Starts and stops the PostgreSQL backend daemon that handles \
 #              all database requests.
 #
 # processname: postmaster
-# pidfile:     /var/run/postmaster.pid
+# pidfile:     $POSTGRES_DATA_DIR/postmaster.pid
 
 # Source function library
 . /etc/rc.d/init.d/functions
 # Get network config
 . /etc/sysconfig/network
 
+# Service config defaults
+ALLOW_TCP_CONNECTIONS=no
+ALLOW_USE_SSL=no
+POSTGRES_DATA_DIR=/var/lib/pgsql
+POSTGRES_LOG=/var/log/pgsql
+ENCODING=UNICODE
+
 # Get service config
 if [ -f /etc/sysconfig/postgresql ] ; then
         . /etc/sysconfig/postgresql
-else
-        ALLOW_TCP_CONNECTIONS=no
-       ALLOW_USE_SSL=no
-       POSTGRES_DATA_DIR=/var/lib/pgsql
-       POSTGRES_LOG=/var/log/pgsql
 fi
 
 # Check that networking is up.
 if is_no "${NETWORKING}"; then
-       msg_Network_Down Postgresql
+       msg_network_down PostgreSQL
        exit 1
 fi
 
 # 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
+if [ -f $POSTGRES_DATA_DIR/postmaster.pid ]; then
   if ps -p `head -1 $POSTGRES_DATA_DIR/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
+       # oh, it has crashed
+       rm -f  /var/lock/subsys/postgresql
   fi
 else
-       # it's stoped. 
+       # it's stopped.
        rm -f  /var/lock/subsys/postgresql
 fi
 
@@ -53,7 +55,7 @@ case "$1" in
   start)
        # Check if the service is already running?
        if [ -f /var/lock/subsys/postgresql ]; then
-               msg_Already_Running PostgreSQL
+               msg_already_running PostgreSQL
        else    
                if is_yes "$ALLOW_USE_SSL"; then
                        if is_no "$ALLOW_TCP_CONNECTIONS"; then
@@ -69,25 +71,19 @@ case "$1" in
                fi
                
                # Sanity check
-               [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
+               [ -e /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
+               [ -f /tmp/.s.PGSQL.5432.lock ] || rm -f /tmp/.s.PGSQL.5432.lock
                
                # 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
+                   if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.2' ]; 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"
+                   echo "Postgresql database not initialized. Try \"$0 init\" before start."
+                   exit 1
                fi
                
                msg_starting PostgreSQL 
@@ -98,13 +94,15 @@ case "$1" in
                    $(is_yes "$POSTGRES_QUIET" && echo '-S') \
                    $(is_yes "$POSTGRES_DISABLE_FSYNC" && echo '-F') \
                    $(is_yes "$ALLOW_TCP_CONNECTIONS" && echo '-i') \
-                   $(is_yes "$ALLOW_USE_SSL" && echo '-l')";
+                   $(is_yes "$ALLOW_USE_SSL" && echo '-l') \
+                   $([ "$BUFFERS" ] && echo \-B $BUFFERS) \
+                   $([ "$MAXCONN" ] && echo \-N $MAXCONN)";
 
                TMPDIR=/tmp su postgres -c "\
-                       $(echo "/usr/bin/pg_ctl start $PGSQL_CMDLINE -l $POSTGRES_LOG") \
+                       $(echo "/usr/bin/pg_ctl start -w $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
@@ -118,10 +116,10 @@ case "$1" in
   stop)
 
        if [ ! -f /var/lock/subsys/postgresql ]; then
-               msg_Not_Running PostgreSQL
+               msg_not_running PostgreSQL
                exit 0  
        fi
-       msg_stopping postgreSQL
+       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"
@@ -133,7 +131,7 @@ case "$1" in
        else
                deltext; ok
        fi
-       rm -f /var/run/postmaster.pid
+       rm -f $POSTGRES_DATA_DIR/postmaster.pid
        rm -f /var/lock/subsys/postgresql
        ;;
   status)
@@ -146,10 +144,10 @@ case "$1" in
        ;;
   reload)
        if [ ! -f /var/lock/subsys/postgresql ]; then
-               msg_Not_Running PostgreSQL
+               msg_not_running PostgreSQL
                exit 0  
        fi
-       msg_reloading postgreSQL
+       msg_reloading PostgreSQL
        busy
 
        PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
@@ -173,8 +171,36 @@ case "$1" in
                exit 1
        fi
        ;;
+    init)
+       if [ -f "$POSTGRES_DATA_DIR/PG_VERSION" ]; then
+           echo "Seems that database is initialized now. Remove by hand $POSTGRES_DATA_DIR"
+           echo "before initialize database."
+           exit 1
+       fi
+
+       echo -n "Specify encoding for pgsql database (eg: LATIN2, KOI8) [$ENCODING]: "
+       read new_encoding
+       ENCODING=${new_encoding:-$ENCODING}
+
+       show "Creating initial postgresql database using $ENCODING encoding"
+       started
+
+        # 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 -s /bin/sh -c "LD_LIBRARY_PATH=/usr/lib \
+                       initdb --pgdata=$POSTGRES_DATA_DIR \
+                       -L /usr/share/postgresql -E $ENCODING"
+
+       echo "REMEMBER to setup password for user \"postgres\"!"
+       ;;
   *)
-       msg_Usage "$0 {start|stop|status|restart|reload}"
+       msg_usage "$0 {start|stop|status|restart|reload}"
        exit 1
 esac
 
This page took 0.044722 seconds and 4 git commands to generate.