summaryrefslogtreecommitdiff
path: root/redhat/pgpool.init
blob: fca65cb46ef2c7bf9d3dc23ce37acf7b6c42fcfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
# pgpool    This is the init script for starting up pgpool
#
# chkconfig: - 64 36
# description: Starts and stops the pgpool daemon
# processname: pgpool
# pidfile:	/var/run/pgpool.pid
#
# v1.0.0 Devrim GUNDUZ <devrim@CommandPrompt.com>
# - Initial version of Red Hat / Fedora init script

if [ -r /etc/sysconfig/pgpool ]; then
    . /etc/sysconfig/pgpool
fi

# Source function library.
INITD=/etc/rc.d/init.d
. $INITD/functions

# Get function listing for cross-distribution logic.
TYPESET=`typeset -f|grep "declare"`

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
# We need it for pgpool
[ "${NETWORKING}" = "no" ] && exit 0

# Find the name of the script
NAME=pgpool

# Set defaults for configuration variables
PGPOOLENGINE=/usr/bin
PGPOOLDAEMON=$PGPOOLENGINE/pgpool
PGPOOLCONF=/etc/pgpool.conf
PGPOOLPID=/var/run/pgpool.pid
PGPOOLLOG=/var/log/pgpool.log

test -x $PGPOOLDAEMON || exit 5

# Create the log file if it does not exist
if [ ! -r $PGPOOLLOG ]
then
	touch $PGPOOLLOG
fi

# Check whether the config file exists or not
if [ ! -r /etc/pgpool.conf ]
then
	echo "$PGPOOLCONF not found"
	RETVAL=1
	failure	
	exit
fi

script_result=0

start(){
	PGPOOL_START=$"Starting ${NAME} service: "

	echo -n "$PGPOOL_START"
	$PGPOOLDAEMON -f $PGPOOLCONF $OPTS & >> "$PGPOOLLOG" 2>&1 < /dev/null
	sleep 2

	pid=`pidof -s "$PGPOOLDAEMON"`
	if [ $pid ] 
	then
		success "$PGPOOL_START"
		touch /var/lock/subsys/${NAME}
		echo
	else
		failure "$PSQL_START"
		echo
		script_result=1
	fi
}

stop(){
	echo -n $"Stopping ${NAME} service: "
        if [ $UID -ne 0 ]; then
                RETVAL=1
                failure
        else
                killproc /usr/bin/pgpool
                RETVAL=$?
                [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/${NAME}
        fi;
        echo
        return $RETVAL
}

switch() {
	echo -n $"Sending switchover request to $NAME "
	$PGPOOLDAEMON switch >> "$PGPOOLLOG" 2>&1 < /dev/null
	RETVAL=$?
	echo
	if [ $RETVAL -eq 0 ] 
	then
		echo_success
	else
		echo_failure
	fi
	echo
}

restart(){
    stop
    start
}

reload(){
echo -n $"Reloading ${NAME}: "
   if [ -n "`pidfileofproc $PGPOOLDAEMON`" ] ; then
      killproc $PGPOOLDAEMON -HUP
   else
      failure $"Reloading ${NAME}"
   fi
   RETVAL=$?
   echo
}

condrestart(){
    [ -e /var/lock/subsys/${NAME} ] && restart
}

condstop(){
    [ -e /var/lock/subsys/${NAME} ] && stop
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  switch)
        switch
        ;;
  status)
        status pgpool
        script_result=$?
        ;;
  restart)
        restart
        ;;
  reload|force-reload)
        reload
        ;;
  condrestart)
        condrestart
        ;;
  condstop)
        condstop
        ;;
  *)
        echo $"Usage: $0 {start|stop|switch|status|restart|condrestart|condstop|reload|force-reload}"
        exit 1
esac

exit $script_result