Ubuntu launchpad bug report https://bugs.launchpad.net/ubuntu/+source/haproxy/+bug/1325847
attachment: patch for current init script (haproxy 1.4.25) ----------------------------- Jetzt zum 1/2 Preis ÖAMTC Mitglied werden Rechtzeitig vor dem Urlaub alle Clubvorteile sichern, wie z.B. gratis Reise-Infoset, Pannenhilfe, tolle Preisvorteile bei Partnern weltweit. www.oeamtc.at/club ---------------------------------------- Wichtiger Hinweis/Important Information: Dieses E-Mail samt Anlagen („E-Mail“) dient nur zur Information. Erklärungen via E-Mail sind nicht rechtsverbindlich, sondern bedürfen der schriftlichen Bestätigung samt firmenmäßiger/statutenmäßiger Unterfertigung durch Mitglieder der Geschäftsleitung in vertretungsbefugter Anzahl. Für die Richtigkeit oder Vollständigkeit der übermittelten Informationen/Daten, für Übermittlungsfehler, für fehlgeleitete E-Mails oder für einen verspäteten Empfang wird nicht gehaftet. Eigene elektronische Empfangs- oder Lesebestätigungen gelten nicht als Bestätigung für den Erhalt eines E-Mails. Der Inhalt dieses E-Mails ist vertraulich. Wenn Sie nicht der angegebene Adressat oder dessen Vertreter sind, informieren Sie bitte umgehend den Absender und löschen Sie dieses E-Mail von Ihrem System. Die unerlaubte Weitergabe oder Nutzung ist nicht gestattet. This e-mail and any attachment (“e-mail”) serves information purposes only. Statements via e-mail are not legally binding but require written confirmation including the signatures of the required number of managing directors under statutory provisions. We are not liable for the accuracy and sufficiency of the provided information/data, for any transmission error, misdirection, loss or delay of an e-mail. Electronic reading receipts are no confirmation for receipt of an e-mail. This e-mail is confidential. If you are not the addressee or his representative, please notify the sender immediately and delete this e-mail from your system. Any disclosure or use is prohibited. ----------------------------------------
--- haproxy.init 2014-04-16 11:42:52.365613000 +0200 +++ haproxy_conf.d.init 2014-06-03 09:24:17.746550000 +0200 @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ### BEGIN INIT INFO # Provides: haproxy # Required-Start: $local_fs $network $remote_fs @@ -9,159 +9,187 @@ # Description: This file should be used to start and stop haproxy. ### END INIT INFO -# Author: Arnaud Cornet <acor...@debian.org> +# Authors: +# Arnaud Cornet <acor...@debian.org> +# David Gabriel <d...@oeamtc.at> + +# added missing features: +# - configtest (automatically run before start/reload/restart) +# - support for conf.d folder to load additional config files PATH=/sbin:/usr/sbin:/bin:/usr/bin PIDFILE=/var/run/haproxy.pid -CONFIG=/etc/haproxy/haproxy.cfg HAPROXY=/usr/sbin/haproxy -EXTRAOPTS= +GLOBALCONFIG="/etc/haproxy/haproxy.cfg" +SITECONFIG=$(find /etc/haproxy/conf.d/ -type f -name '*.cfg' 2>/dev/null | sed -e ':a;N;$!ba;s/\n/ -f /g'i) ENABLED=0 +EXTRAOPTS= -test -x $HAPROXY || exit 0 +if [[ ! -x ${HAPROXY} ]]; then log_daemon_msg "haproxy binary not found, aborting!" && exit 1; fi +if [[ ! -f "${GLOBALCONFIG}" ]]; then log_daemon_msg "haproxy config not found, aborting!"; exit 1; fi if [ -e /etc/default/haproxy ]; then . /etc/default/haproxy fi +test "${ENABLED}" != "0" || log_daemon_msg "haproxy administratively disabled (check /etc/default/haproxy), aborting."; exit 0 -test -f "$CONFIG" || exit 0 -test "$ENABLED" != "0" || exit 0 +if [[ -z ${SITECONFIG} ]]; then + CONFIG="-f ${GLOBALCONFIG}" +else + CONFIG="-f ${GLOBALCONFIG} -f ${SITECONFIG}" +fi [ -f /etc/default/rcS ] && . /etc/default/rcS . /lib/lsb/init-functions +haproxy_check() { + if ! ${HAPROXY} -q -c ${CONFIG} 2>/dev/null; then + echo -en " * Configuration errors detected, aborting further actions!\n" + echo -en " * Run:\n\n ${HAPROXY} -c ${CONFIG}\n\n * Fix any errors and try again.\n" + exit 1 + else + log_daemon_msg "Looking good :)" + fi +} -haproxy_start() -{ - start-stop-daemon --start --pidfile "$PIDFILE" \ - --exec $HAPROXY -- -f "$CONFIG" -D -p "$PIDFILE" \ - $EXTRAOPTS || return 2 - return 0 +haproxy_start() { + start-stop-daemon \ + --start \ + --pidfile "${PIDFILE}" \ + --exec ${HAPROXY} -- \ + ${CONFIG} \ + -D \ + -p ${PIDFILE} \ + ${EXTRAOPTS} || return 2 + return 0 } -haproxy_stop() -{ - if [ ! -f $PIDFILE ] ; then - # This is a success according to LSB - return 0 - fi - for pid in $(cat $PIDFILE) ; do - /bin/kill $pid || return 4 - done - rm -f $PIDFILE - return 0 +haproxy_stop() { + if [ ! -f ${PIDFILE} ] ; then + # This is a success according to LSB + return 0 + fi + + for pid in $(cat ${PIDFILE}) ; do + /bin/kill $pid || return 4 + done + rm -f ${PIDFILE} + return 0 } -haproxy_reload() -{ - $HAPROXY -f "$CONFIG" -p $PIDFILE -D $EXTRAOPTS -sf $(cat $PIDFILE) \ - || return 2 - return 0 +haproxy_reload() { + ${HAPROXY} ${CONFIG} -p ${PIDFILE} -D ${EXTRAOPTS} -sf $(cat ${PIDFILE}) || return 2 + return 0 } -haproxy_status() -{ - if [ ! -f $PIDFILE ] ; then - # program not running - return 3 - fi - - for pid in $(cat $PIDFILE) ; do - if ! ps --no-headers p "$pid" | grep haproxy > /dev/null ; then - # program running, bogus pidfile - return 1 - fi - done +haproxy_status() { + if [ ! -f ${PIDFILE} ] ; then + # program not running + return 3 + fi + + for pid in $(cat ${PIDFILE}) ; do + if ! ps --no-headers p "$pid" | grep haproxy > /dev/null ; then + # program running, bogus pidfile + return 1 + fi + done - return 0 + return 0 } - case "$1" in -start) - log_daemon_msg "Starting haproxy" "haproxy" - haproxy_start - ret=$? - case "$ret" in - 0) - log_end_msg 0 - ;; - 1) - log_end_msg 1 - echo "pid file '$PIDFILE' found, haproxy not started." - ;; - 2) - log_end_msg 1 - ;; - esac - exit $ret - ;; -stop) - log_daemon_msg "Stopping haproxy" "haproxy" - haproxy_stop - ret=$? - case "$ret" in - 0|1) - log_end_msg 0 - ;; - 2) - log_end_msg 1 - ;; - esac - exit $ret - ;; -reload|force-reload) - log_daemon_msg "Reloading haproxy" "haproxy" - haproxy_reload - ret=$? - case "$ret" in - 0|1) - log_end_msg 0 - ;; - 2) - log_end_msg 1 - ;; - esac - exit $ret - ;; -restart) - log_daemon_msg "Restarting haproxy" "haproxy" - haproxy_stop - haproxy_start - ret=$? - case "$ret" in - 0) - log_end_msg 0 - ;; - 1) - log_end_msg 1 - ;; - 2) - log_end_msg 1 - ;; - esac - exit $ret - ;; -status) - haproxy_status - ret=$? - case "$ret" in - 0) - echo "haproxy is running." - ;; - 1) - echo "haproxy dead, but $PIDFILE exists." - ;; - *) - echo "haproxy not running." - ;; - esac - exit $ret - ;; -*) - echo "Usage: /etc/init.d/haproxy {start|stop|reload|restart|status}" - exit 2 - ;; -esac + configtest) + log_daemon_msg "Running haproxy configtest..." + haproxy_check + ;; + + start) + log_daemon_msg "Running haproxy configtest..." + haproxy_check + log_daemon_msg "Starting haproxy" "haproxy" + haproxy_start + ret=$? + case "$ret" in + 0) log_end_msg 0 + ;; + + 1) log_end_msg 1 + echo "pid file '${PIDFILE}' found, haproxy not started." + ;; + + 2) log_end_msg 1 + ;; + esac + exit $ret + ;; + + stop) + log_daemon_msg "Stopping haproxy" "haproxy" + haproxy_stop + ret=$? + case "$ret" in + 0|1) log_end_msg 0 + ;; + + 2) log_end_msg 1 + ;; + esac + exit $ret + ;; + + reload|force-reload) + log_daemon_msg "Running haproxy configtest..." + haproxy_check + log_daemon_msg "Reloading" "haproxy" + haproxy_reload + case "$?" in + 0|1) log_end_msg 0 + ;; + + 2) log_end_msg 1 + ;; + esac + ;; + + restart) + log_daemon_msg "Running haproxy configtest..." + haproxy_check + log_daemon_msg "Restarting" "haproxy" + haproxy_stop + haproxy_start + case "$?" in + 0) log_end_msg 0 + ;; + + 1) log_end_msg 1 + ;; + + 2) log_end_msg 1 + ;; + esac + ;; + + status) + haproxy_status + ret=$? + case "$ret" in + 0) echo "haproxy is running." + ;; + + 1) echo "haproxy dead, but ${PIDFILE} exists." + ;; + + *) echo "haproxy not running."; ret="3" # return code 3, so pacemaker knows service should not be running + ;; + esac + exit $ret + ;; + + *) + echo "Usage: /etc/init.d/haproxy {configtest|start|stop|reload|restart|status}" + exit 2 + ;; +esac :