blob: 4b3a0e619b03247e18f865363733546e1d3297ff [file] [log] [blame]
#!/sbin/runscript
# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$
extra_commands="checkconfig"
extra_started_commands="reload"
command="/usr/bin/haproxy"
pidfile="${HAPROXY_PIDFILE:-/var/run/${SVCNAME}.pid}"
configs=
if [ -z "${CONFIGS}" ]; then
if [ -f "/etc/haproxy/${SVCNAME}.cfg" ]; then
CONFIGS=/etc/haproxy/${SVCNAME}.cfg
elif [ -f "/etc/${SVCNAME}.cfg" ]; then
CONFIGS=/etc/${SVCNAME}.cfg # Deprecated
fi
fi
for conf in $CONFIGS; do
configs="${configs} -f ${conf}"
done
command_args="-D -p ${pidfile} ${configs} ${HAPROXY_OPTS}"
depend() {
need net
use dns logger
}
checkconfig() {
if [ -z "${CONFIGS}" ]; then
eerror "No config(s) has been specified"
return 1
fi
for conf in $CONFIGS; do
if [ ! -f "${conf}" ]; then
eerror "${conf} does not exist!"
return 1
fi
done
ebegin "Checking ${CONFIGS}"
$command -q -c $configs $HAPROXY_OPTS
eend $?
}
start_pre() {
if [ "${RC_CMD}" != "restart" ]; then
checkconfig || return 1
fi
}
stop_pre() {
if [ "${RC_CMD}" = "restart" ]; then
checkconfig || return 1
fi
}
reload() {
checkconfig || { eerror "Reloading failed, please fix your config(s) first"; return 1; }
if [ "$(command -v reload_seamless)" = "reload_seamless" ]; then
einfo "Calling user-defined reload_seamless()"
reload_seamless || { eerror "reload_seamless() failed!"; return 1; }
fi
ebegin "Reloading ${SVCNAME}"
$command -D -p "${pidfile}" $configs $HAPROXY_OPTS -sf $(cat "${pidfile}")
eend $?
}