Skip to content

Instantly share code, notes, and snippets.

@phil-monroe
Created January 11, 2013 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phil-monroe/4507299 to your computer and use it in GitHub Desktop.
Save phil-monroe/4507299 to your computer and use it in GitHub Desktop.
HAProxy init.d script.
#!/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