]> git.8kb.co.uk Git - pgpool-ii/pgpool-ii_2.2.5/blob - redhat/pgpool.init
Attempt to send a proper failure message to frontend when authentication
[pgpool-ii/pgpool-ii_2.2.5] / redhat / pgpool.init
1 #!/bin/sh
2 # pgpool    This is the init script for starting up pgpool-II
3 #
4 # chkconfig: - 64 36
5 # description: Starts and stops the pgpool daemon
6 # processname: pgpool
7 # pidfile:      /var/run/pgpool.pid
8 #
9 # v1.0.0 Devrim GUNDUZ <devrim@CommandPrompt.com>
10 # - Initial version of Red Hat / Fedora init script
11 #
12 # v2.2 Devrim GUNDUZ <devrim@CommandPrompt.com>
13 # - New and improved version which has some fixes.
14
15 if [ -r /etc/sysconfig/pgpool ]; then
16     . /etc/sysconfig/pgpool
17 fi
18
19 # Source function library.
20 INITD=/etc/rc.d/init.d
21 . $INITD/functions
22
23 # Get function listing for cross-distribution logic.
24 TYPESET=`typeset -f|grep "declare"`
25
26 # Get config.
27 . /etc/sysconfig/network
28
29 # Check that networking is up.
30 # We need it for pgpool
31 [ "${NETWORKING}" = "no" ] && exit 0
32
33 # Find the name of the script
34 NAME=`basename $0`
35 if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]
36 then
37         NAME=${NAME:3}
38 fi
39
40 # Set defaults for configuration variables
41 PGPOOLENGINE=/usr/bin
42 PGPOOLDAEMON=$PGPOOLENGINE/pgpool
43 PGPOOLCONF=/etc/pgpool-II/pgpool.conf
44 PGPOOLPIDDIR=/var/run/pgpool
45 PGPOOLLOG=/var/log/pgpool.log
46
47 test -x $PGPOOLDAEMON || exit 5
48
49 # Check whether the config file exists or not
50 if [ ! -r $PGPOOLCONF ]
51 then
52         echo "$PGPOOLCONF not found"
53         RETVAL=1
54         failure 
55         exit
56 fi
57
58 # Create the log file if it does not exist
59 if [ ! -x $PGPOOLLOG ]
60 then
61         touch $PGPOOLLOG
62         chown postgres: $PGPOOLLOG
63 fi
64
65 if [ ! -d $PGPOOLPIDDIR ]
66 then
67         mkdir $PGPOOLPIDDIR
68         chown postgres: $PGPOOLPIDDIR
69 fi
70
71 script_result=0
72
73 start(){
74         pid=`pidof -s "$PGPOOLDAEMON"`
75         if [ $pid ]
76         then
77                 echo "pgpool is already running with pid $pid"
78                 failure "$PGPOQL_START"
79                 echo
80                 script_result=1
81                 exit 1
82         fi
83
84         PGPOOL_START=$"Starting ${NAME} service: "
85
86         echo -n "$PGPOOL_START"
87
88         $PGPOOLDAEMON -f $PGPOOLCONF $OPTS & >> "$PGPOOLLOG" 2>&1 < /dev/null
89         sleep 2
90
91         pid=`pidof -s "$PGPOOLDAEMON"`
92         if [ $pid ] 
93         then
94                 success "$PGPOOL_START"
95                 touch /var/lock/subsys/${NAME}
96                 echo
97         else
98                 failure "$PGPOQL_START"
99                 echo
100                 script_result=1
101         fi
102 }
103
104 stop(){
105         echo -n $"Stopping ${NAME} service: "
106         if [ $UID -ne 0 ]; then
107                 RETVAL=1
108                 failure
109         else
110                 killproc /usr/bin/pgpool
111 #               $PGPOOLDAEMON stop & >> "$PGPOOLLOG" 2>&1 < /dev/null
112                 RETVAL=$?
113                 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/${NAME}
114         fi;
115         echo
116         return $RETVAL
117 }
118
119 switch() {
120         echo -n $"Sending switchover request to $NAME "
121         $PGPOOLDAEMON -f $PGPOOLCONF switch >> "$PGPOOLLOG" 2>&1 < /dev/null
122         RETVAL=$?
123         echo
124         if [ $RETVAL -eq 0 ] 
125         then
126                 echo_success
127         else
128                 echo_failure
129         fi
130         echo
131 }
132
133 restart(){
134     stop
135     start
136 }
137
138 reload(){
139         echo -n $"Reloading ${NAME}: "
140
141         if [ -n "`pidfileofproc $PGPOOLDAEMON`" ] ; then
142                 killproc $PGPOOLDAEMON -HUP
143         else
144                 failure $"Reloading ${NAME}"
145         fi
146         RETVAL=$?
147         echo
148 }
149
150 condrestart(){
151         [ -e /var/lock/subsys/${NAME} ] && restart
152 }
153
154 condstop(){
155         [ -e /var/lock/subsys/${NAME} ] && stop
156 }
157
158 # See how we were called.
159 case "$1" in
160   start)
161         start
162         ;;
163   stop)
164         stop
165         ;;
166   switch)
167         switch
168         ;;
169   status)
170         status pgpool
171         script_result=$?
172         ;;
173   restart)
174         restart
175         ;;
176   reload|force-reload)
177         reload
178         ;;
179   condrestart)
180         condrestart
181         ;;
182   condstop)
183         condstop
184         ;;
185   *)
186         echo $"Usage: $0 {start|stop|switch|status|restart|condrestart|condstop|reload|force-reload}"
187         exit 1
188 esac
189
190 exit $script_result