Created
January 13, 2012 22:47
-
-
Save spikegrobstein/1609189 to your computer and use it in GitHub Desktop.
pgpool init script for centos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# pgpool - the postgres replication daemon. | |
# | |
# chkconfig: 2345 64 36 | |
# description: start and stop the pgpool daemon | |
### BEGIN INIT INFO | |
# Provides: pgpool | |
# Required-Start: $local_fs $network $remote_fs | |
# Should-Start: ypbind nscd ldap ntpd xntpd | |
# Required-Stop: $local_fs $network $remote_fs | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: start and stop pgpool | |
# Description: pgpool is pure awesomeness. | |
### END INIT INFO | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
# command that needs to run: | |
# sudo -u postgres pgpool -f /usr/local/etc/pgpool.conf -F /usr/local/etc/pcp.conf | |
exec="/usr/local/bin/pgpool" | |
prog="pgpool" | |
user="postgres" | |
pgpool_config="/usr/local/etc/pgpool.conf" | |
pcp_config="/usr/local/etc/pcp.conf" | |
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog | |
lockfile=/var/lock/subsys/$prog | |
start() { | |
[ -x $exec ] || exit 5 | |
[ -f $pgpool_config ] || exit 6 | |
[ -f $pcp_config ] || exit 6 | |
echo -n $"Starting $prog: " | |
# if not running, start it up here, usually something like "daemon $exec" | |
pgpool_command | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && touch $lockfile | |
return $retval | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
# stop it here, often "killproc $prog" | |
echo pgpool_command stop | |
pgpool_command stop | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && rm -f $lockfile | |
return $retval | |
} | |
restart() { | |
stop | |
start | |
} | |
reload() { | |
pgpool_command reload | |
} | |
force_reload() { | |
restart | |
} | |
rh_status() { | |
# run checks to determine if the service is running or use generic status | |
status $prog | |
} | |
rh_status_q() { | |
rh_status >/dev/null 2>&1 | |
} | |
pgpool_command() { | |
sudo -u $user $exec -f "$pgpool_config" -F "$pcp_config" $1 | |
} | |
case "$1" in | |
start) | |
rh_status_q && exit 0 | |
$1 | |
;; | |
stop) | |
rh_status_q || exit 0 | |
$1 | |
;; | |
restart) | |
$1 | |
;; | |
reload) | |
rh_status_q || exit 7 | |
$1 | |
;; | |
force-reload) | |
force_reload | |
;; | |
status) | |
rh_status | |
;; | |
condrestart|try-restart) | |
rh_status_q || exit 0 | |
restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | |
exit 2 | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment