Created
August 17, 2012 01:56
-
-
Save ricardokrieg/3375210 to your computer and use it in GitHub Desktop.
HAProxy daemon script
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 | |
# | |
# processname: haproxy | |
# config: /opt/haproxy/haproxy.cfg | |
# pidfile: /var/run/haproxy.pid | |
[ -f /opt/haproxy/haproxy.cfg ] || exit 1 | |
RETVAL=0 | |
start() { | |
/usr/bin/haproxy -c -q -f /opt/haproxy/haproxy.cfg | |
if [ $? -ne 0 ]; then | |
echo "Errors found in configuration file, check it with 'haproxy check'." | |
return 1 | |
fi | |
echo -n "Starting haproxy: " | |
/usr/bin/haproxy -D -f /opt/haproxy/haproxy.cfg -p /var/run/haproxy.pid | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/haproxy | |
return $RETVAL | |
} | |
stop() { | |
echo -n "Shutting down haproxy: " | |
killproc haproxy -USR1 | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/haproxy | |
[ $RETVAL -eq 0 ] && rm -f /var/run/haproxy.pid | |
return $RETVAL | |
} | |
restart() { | |
/usr/bin/haproxy -c -q -f /opt/haproxy/haproxy.cfg | |
if [ $? -ne 0 ]; then | |
echo "Errors found in configuration file, check it with 'haproxy check'." | |
return 1 | |
fi | |
stop | |
start | |
} | |
reload() { | |
/usr/bin/haproxy -c -q -f /opt/haproxy/haproxy.cfg | |
if [ $? -ne 0 ]; then | |
echo "Errors found in configuration file, check it with 'haproxy check'." | |
return 1 | |
fi | |
/usr/bin/haproxy -D -f /opt/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid) | |
} | |
check() { | |
/usr/bin/haproxy -c -q -V -f /opt/haproxy/haproxy.cfg | |
} | |
rhstatus() { | |
status haproxy | |
} | |
condrestart() { | |
[ -e /var/lock/subsys/haproxy ] && restart || : | |
} | |
# See how we were called. | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
reload) | |
reload | |
;; | |
condrestart) | |
condrestart | |
;; | |
status) | |
rhstatus | |
;; | |
check) | |
check | |
;; | |
*) | |
echo $"Usage: haproxy {start|stop|restart|reload|condrestart|status|check}" | |
exit 1 | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment