Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Setting up haproxy as a daemon on your ubuntu server
#!/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
@wbailey
Owner

Once the script above is available on /etc/init.d do the following (Ubuntu/Debian)

cd /etc/init.d
sudo update-rc.d haproxyd defaults

then you can

$ sudo service haproxyd status
haproxy is running with pid: 4498

@sardaukar
root@ipXX:/etc/init.d# ./haproxy status
haproxy is ./haproxy: line 13: [: 9060: binary operator expected
running with pid: 9060
9062

:(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.