Created
January 11, 2013 01:47
-
-
Save phil-monroe/4507299 to your computer and use it in GitHub Desktop.
HAProxy init.d 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
#!/usr/bin/env bash | |
# haproxyd | |
# Script to start|stop|restart haproxy from /etc/init.d/ | |
# By Phil Monroe. | |
HAPROXY_PATH=/usr/sbin | |
HAPROXY_DAEMON=$HAPROXY_PATH/haproxy | |
HAPROXY_CONFIG=/etc/haproxy/haproxy.cfg | |
test -x $HAPROXY_DAEMON || exit 0 | |
test -f $HAPROXY_CONFIG || exit 1 | |
set -e | |
function getHaproxyPID() { | |
PID=`ps aux | grep 'haproxy -f' | grep -v "grep" | awk '{ print $2 }'` | |
} | |
case $1 in | |
start) | |
echo "Starting haproxy..." | |
$HAPROXY_DAEMON -f $HAPROXY_CONFIG | |
;; | |
restart) | |
echo "Hot restart of haproxy" | |
getHaproxyPID | |
COMMAND="$HAPROXY_DAEMON -f $HAPROXY_CONFIG -sf $PID" | |
echo $COMMAND | |
`$COMMAND` | |
;; | |
stop) | |
echo "Stopping haproxy" | |
getHaproxyPID | |
COMMAND="kill -9 $PID" | |
echo $COMMAND | |
`$COMMAND` | |
;; | |
*) | |
echo "Usage: haproxyd {start|restart|stop}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment