]> git.pld-linux.org Git - packages/postgresql.git/blob - postgresql.init
- release++
[packages/postgresql.git] / postgresql.init
1 #!/bin/sh
2 #
3 # postgresql    This is the init script for starting up the PostgreSQL
4 #               server
5 #
6 # chkconfig:    345 85 15
7 #
8 # description:  Starts and stops the PostgreSQL backend daemon that handles \
9 #               all database requests.
10 #
11 # processname:  postmaster
12 # pidfile:      /var/run/postmaster.pid
13
14 # Source function library
15 . /etc/rc.d/init.d/functions
16
17 # Get network config
18 . /etc/sysconfig/network
19
20 # Get service config
21 if [ -f /etc/sysconfig/postgresql ] ; then
22         . /etc/sysconfig/postgresql
23 else
24         ALLOW_TCP_CONNECTIONS=no
25         POSTGRES_DATA_DIR=/var/lib/psql
26 fi
27
28 # Check that networking is up.
29 if is_no "${NETWORKING}"; then
30         msg_Network_Down Postgresql
31         exit 1
32 fi
33
34 # See how we were called.
35 case "$1" in
36   start)
37         # Check if the service is already running?
38         if [ ! -f /var/lock/subsys/postgresql ]; then
39
40                 # Sanity check
41                 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
42                 STARTTEXT="Starting postgresql"
43                 
44                 # Check for the PGDATA structure
45                 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -d $POSTGRES_DATA_DIR/base/template1 ]; then
46                     # Check version of existing PGDATA
47                     if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '6.5' ]; then
48                         STARTTEXT="$STARTTEXT [Old version. Need to Upgrade]"
49                         show "$STARTTEXT"; fail
50                         exit 1
51                     fi
52                 else
53                     # Create sample database
54                     if [ ! -d $POSTGRES_DATA_DIR ]; then
55                         mkdir -p $POSTGRES_DATA_DIR
56                         chown postgres.postgres $POSTGRES_DATA_DIR
57                     fi
58                     show "Creating postgresql init database"
59                     busy
60                     su postgres -c "LD_LIBRARY_PATH=/usr/lib \
61                         initdb --pgdata=$POSTGRES_DATA_DIR \
62                         --pglib=/usr/lib/pgsql &>/tmp/initdb.pgsql"
63                     deltext; ok
64                 fi
65                 
66                 show "$STARTTEXT"
67                 busy
68                 su postgres -c "/usr/bin/postmaster \
69                         $([ "$ALLOW_TCP_CONNECTIONS" = yes ] && echo "-i") \
70                         $([ -n "$MAX_NUM_BACKENDS" ] && echo "-N $MAX_NUM_BACKENDS") \
71                         $([ -n "POSTGRES_$DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
72                         -o \
73                         $([ "$POSTGRES_QUIET" = yes ] && echo "-Q") \
74                         $([ "$POSTGRES_DIABLE_FSYNC" = yes ] && echo "-F") 2> /dev/null &"
75                 sleep 2
76                 if ps ax | grep -v grep | grep -q postmaster; then
77                         deltext; ok
78                 else
79                         deltext; fail
80                 fi
81         else
82                 msg_Already_Running Postgresql
83         fi
84         touch /var/lock/subsys/postgresql
85         ;;
86   stop)
87         msg_stopping postgresql
88         killproc postmaster
89         sleep 2
90         rm -f /var/run/postmaster.pid
91         rm -f /var/lock/subsys/postgresql
92         ;;
93   status)
94         status postmaster
95         ;;
96   restart|reload)
97         $0 stop
98         $0 start
99         ;;
100   *)
101         msg_Usage "$0 {start|stop|status|restart|reload}"
102         exit 1
103 esac
104
105 exit 0
This page took 0.093468 seconds and 3 git commands to generate.