#!/usr/bin/env bash SSD=/sbin/start-stop-daemon PIDFILE=/var/run/haproxy.pid PROG=/usr/sbin/haproxy OPTS="-f /etc/haproxy.conf" start() { ${SSD} --start -b -m -p ${PIDFILE} -x ${PROG} -- ${OPTS}; } stop() { ${SSD} --stop --remove-pidfile --retry 10 --pidfile "${PIDFILE}"; } status() { ${SSD} --status --pidfile ${PIDFILE} case $? in 0) printf 'running (pid %d)\n' "$(cat ${PIDFILE})" ;; 1) printf 'stopped (stale pidfile found)\n' ;; 3) printf 'stopped\n' ;; 4) printf 'Unknown\n' ;; esac } case "${1}" in start) start ;; stop) stop ;; restart) stop && start ;; status) status ;; *) printf 'Action required (start, stop, restart, status)\n' ;; esac