Last active
August 29, 2015 14:04
-
-
Save james-huston/d0b35e1b57d750b980f4 to your computer and use it in GitHub Desktop.
HAProxy init.d script for compiled install in /usr/local for CentOS/AWS
This file contains hidden or 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 | |
# | |
# haproxy | |
# | |
# chkconfig: - 85 15 | |
# description: HAProxy is a free, very fast and reliable solution \ | |
# offering high availability, load balancing, and \ | |
# proxying for TCP and HTTP-based applications | |
# processname: haproxy | |
# config: /usr/local/etc/haproxy/haproxy.cfg | |
# pidfile: /var/run/haproxy.pid | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
# Source networking configuration. | |
. /etc/sysconfig/network | |
# Check that networking is up. | |
[ "$NETWORKING" = "no" ] && exit 0 | |
exec="/usr/local/sbin/haproxy" | |
prog=$(basename $exec) | |
[ -e /usr/local/etc/sysconfig/$prog ] && . /usr/local/etc/sysconfig/$prog | |
lockfile=/var/lock/subsys/haproxy | |
check() { | |
$exec -c -V -f /usr/local/etc/$prog/$prog.cfg | |
} | |
start() { | |
$exec -c -q -f /usr/local/etc/$prog/$prog.cfg | |
if [ $? -ne 0 ]; then | |
echo "Errors in configuration file, check with $prog check." | |
return 1 | |
fi | |
echo -n $"Starting $prog: " | |
# start it up here, usually something like "daemon $exec" | |
daemon $exec -D -f /usr/local/etc/$prog/$prog.cfg -p /var/run/$prog.pid | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && touch $lockfile | |
return $retval | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
# stop it here, often "killproc $prog" | |
killproc $prog | |
retval=$? | |
echo | |
[ $retval -eq 0 ] && rm -f $lockfile | |
return $retval | |
} | |
restart() { | |
$exec -c -q -f /usr/local/etc/$prog/$prog.cfg | |
if [ $? -ne 0 ]; then | |
echo "Errors in configuration file, check with $prog check." | |
return 1 | |
fi | |
stop | |
start | |
} | |
reload() { | |
$exec -c -q -f /usr/local/etc/$prog/$prog.cfg | |
if [ $? -ne 0 ]; then | |
echo "Errors in configuration file, check with $prog check." | |
return 1 | |
fi | |
echo -n $"Reloading $prog: " | |
$exec -D -f /etc/$prog/$prog.cfg -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid) | |
retval=$? | |
echo | |
return $retval | |
} | |
force_reload() { | |
restart | |
} | |
fdr_status() { | |
status $prog | |
} | |
case "$1" in | |
start|stop|restart|reload) | |
$1 | |
;; | |
force-reload) | |
force_reload | |
;; | |
check) | |
check | |
;; | |
status) | |
fdr_status | |
;; | |
condrestart|try-restart) | |
[ ! -f $lockfile ] || restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}" | |
exit 2 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment