Created
December 22, 2011 06:24
-
-
Save wbailey/1509227 to your computer and use it in GitHub Desktop.
Setting up haproxy as a daemon on your ubuntu server
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/bash | |
CONFIG=/etc/haproxy/haproxy.cfg | |
DAEMON=$(which haproxy) | |
function get_pid() { | |
PID=$(ps aux | grep haproxy | grep -v grep | awk '{print $2}') | |
} | |
function get_status() { | |
get_pid | |
if [ -z $PID ]; then | |
echo 'not running' | |
else | |
echo "running with pid: $PID" | |
fi | |
} | |
case $1 in | |
start) | |
echo -n 'starting haproxy ' | |
$DAEMON -f $CONFIG | |
get_status | |
;; | |
restart) | |
echo -n 'restarting haproxy ' | |
get_pid | |
$DAEMON -f $CONFIG -sf $PID | |
get_status | |
;; | |
stop) | |
echo -n 'stopping haproxy ' | |
get_pid | |
kill -9 $PID | |
get_status | |
;; | |
status) | |
echo -n 'haproxy is ' | |
get_status | |
;; | |
*) | |
echo "Usage: haproxyd {start|restart|stop|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:(