]> git.pld-linux.org Git - packages/postgresql.git/blob - postgresql.init
- partialy fixed, dirty hack (sleep after starting), but works
[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         ALLOW_USE_SSL=no
26         POSTGRES_DATA_DIR=/var/lib/pgsql
27         POSTGRES_LOG=/var/log/pgsql
28 fi
29
30 # Check that networking is up.
31 if is_no "${NETWORKING}"; then
32         msg_Network_Down Postgresql
33         exit 1
34 fi
35
36 # check if postmaster is realy alive
37 if [ -f /var/lib/pgsql/postmaster.pid ]; then
38  if ps -p `head -1 /var/lib/pgsql/postmaster.pid` > /dev/null ; then
39          #ok. it's alive
40         echo > /dev/null;
41  else
42          # oh, it has crashed
43          rm -f  /var/lock/subsys/postgresql
44  fi
45 else
46         # it's stoped. 
47         rm -f  /var/lock/subsys/postgresql
48 fi
49
50
51 # See how we were called.
52 case "$1" in
53   start)
54         # Check if the service is already running?
55         if [ -f /var/lock/subsys/postgresql ]; then
56                 msg_Already_Running PostgreSQL
57         else    
58                 if is_yes "$ALLOW_USE_SSL"; then
59                         if is_no "$ALLOW_TCP_CONNECTIONS"; then
60                                 nls "You must enable ALLOW_TCP_CONNECTIONS in order to use SSL"
61                                 exit 1
62                         elif [ ! -f "$POSTGRES_DATA_DIR/server.key" ]; then
63                                 nls "$POSTGRES_DATA_DIR/server.key not found!"
64                                 exit 1
65                         elif [ ! -f "$POSTGRES_DATA_DIR/server.crt" ]; then
66                                 nls "$POSTGRES_DATA_DIR/server.crt not found!"
67                                 exit 1
68                         fi
69                 fi
70                 
71                 # Sanity check
72                 [ -f /tmp/.s.PGSQL.5432 ] || rm -f /tmp/.s.PGSQL.5432
73                 
74                 # Check for the PGDATA structure
75                 if [ -f $POSTGRES_DATA_DIR/PG_VERSION ] && [ -f $POSTGRES_DATA_DIR/global/pg_control ]; then
76                     # Check version of existing PGDATA
77                     if [ `cat $POSTGRES_DATA_DIR/PG_VERSION` != '7.1' ]; then
78                         show "Databases created under incompatibile version. Migrate them first."; fail
79                         exit 1
80                     fi
81                 else
82                     # Create sample database
83                     if [ ! -d $POSTGRES_DATA_DIR ]; then
84                         mkdir -p $POSTGRES_DATA_DIR
85                         chown postgres.postgres $POSTGRES_DATA_DIR
86                         chmod 700 $POSTGRES_DATA_DIR
87                     fi
88                     TMPDIR=/tmp su postgres -c "LD_LIBRARY_PATH=/usr/lib \
89                         initdb --pgdata=$POSTGRES_DATA_DIR \
90                         -L /usr/share/postgresql"
91                 fi
92                 
93                 msg_starting PostgreSQL 
94                 busy
95                 PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
96                     $(is_yes "$POSTGRES_QUIET" && echo '-s')";
97                 POSTMASTER_OPTIONS=" \
98                     $(is_yes "$POSTGRES_QUIET" && echo '-S') \
99                     $(is_yes "$POSTGRES_DISABLE_FSYNC" && echo '-F') \
100                     $(is_yes "$ALLOW_TCP_CONNECTIONS" && echo '-i') \
101                     $(is_yes "$ALLOW_USE_SSL" && echo '-l')";
102
103                 TMPDIR=/tmp su postgres -c "\
104                         $(echo "/usr/bin/pg_ctl start $PGSQL_CMDLINE -l $POSTGRES_LOG") \
105                         $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
106                         $(echo "2>&1 >/dev/null")";
107                 
108                 usleep 100000
109                 out=`status postmaster`
110                 if [ $? -eq 0 ]; then 
111                     deltext; ok
112                 else
113                     deltext; fail 
114                     exit 1      
115                 fi
116         fi
117         touch /var/lock/subsys/postgresql
118         ;;
119   stop)
120
121         if [ ! -f /var/lock/subsys/postgresql ]; then
122                 msg_Not_Running PostgreSQL
123                 exit 0  
124         fi
125         msg_stopping postgreSQL
126         busy
127         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
128         TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl stop $PGSQL_CMDLINE -m fast 2>&1 >/dev/null"
129         out=`status postmaster`
130         if [ $? -eq 0 ]; then
131                 deltext; fail
132                 echo -e "\n$out";
133                 exit 1
134         else
135                 deltext; ok
136         fi
137         rm -f /var/run/postmaster.pid
138         rm -f /var/lock/subsys/postgresql
139         ;;
140   status)
141         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR")";
142         TMPDIR=/tmp su postgres -c "/usr/bin/pg_ctl status $PGSQL_CMDLINE"
143         ;;
144   restart)
145         $0 stop
146         $0 start
147         ;;
148   reload)
149         if [ ! -f /var/lock/subsys/postgresql ]; then
150                 msg_Not_Running PostgreSQL
151                 exit 0  
152         fi
153         msg_reloading postgreSQL
154         busy
155
156         PGSQL_CMDLINE="$([ -n "$POSTGRES_DATA_DIR" ] && echo "-D $POSTGRES_DATA_DIR") \
157             $([ "$POSTGRES_QUIET". = yes. ] && echo '-s')";
158         POSTMASTER_OPTIONS=" \
159             $([ "$POSTGRES_QUIET". = yes. ] && echo '-S') \
160             $([ "$POSTGRES_DISABLE_FSYNC". = yes. ] && echo '-F') \
161             $([ "$ALLOW_TCP_CONNECTIONS". = yes. ] && echo '-i')";
162
163         TMPDIR=/tmp su postgres -c "\
164                 $(echo "/usr/bin/pg_ctl restart $PGSQL_CMDLINE -l $POSTGRES_LOG") \
165                 $([ "$POSTMASTER_OPTIONS". != . ] && echo "-o '$POSTMASTER_OPTIONS'") \
166                 $(echo "2>&1 >/dev/null")";
167
168         out=`status postmaster`
169         if [ $? -eq 0 ]; then
170                 deltext; ok
171         else
172                 deltext; fail
173                 echo -e "\n$out";
174                 exit 1
175         fi
176         ;;
177   *)
178         msg_Usage "$0 {start|stop|status|restart|reload}"
179         exit 1
180 esac
181
182 exit 0
This page took 0.048457 seconds and 4 git commands to generate.