diff options
author | Pav Lucistnik <pav@FreeBSD.org> | 2010-09-03 21:49:54 +0000 |
---|---|---|
committer | Pav Lucistnik <pav@FreeBSD.org> | 2010-09-03 21:49:54 +0000 |
commit | 847bdaad29a89e237943d9c3b0b98187fe9800eb (patch) | |
tree | 67ddd4d46591db32eb0467d06cc58d48806f2fd0 /net/haproxy-devel/files/haproxy.in | |
parent | 05717c697f543cfa3ec8a57b403da9130c8b8668 (diff) | |
download | ports-847bdaad29a89e237943d9c3b0b98187fe9800eb.tar.gz ports-847bdaad29a89e237943d9c3b0b98187fe9800eb.zip |
Notes
Diffstat (limited to 'net/haproxy-devel/files/haproxy.in')
-rw-r--r-- | net/haproxy-devel/files/haproxy.in | 109 |
1 files changed, 78 insertions, 31 deletions
diff --git a/net/haproxy-devel/files/haproxy.in b/net/haproxy-devel/files/haproxy.in index c54a12033cca..8127c9adffe6 100644 --- a/net/haproxy-devel/files/haproxy.in +++ b/net/haproxy-devel/files/haproxy.in @@ -1,52 +1,99 @@ #!/bin/sh -# -# $FreeBSD$ -# # PROVIDE: haproxy -# REQUIRE: NETWORKING SERVERS -# BEFORE: DAEMON +# REQUIRE: DAEMON # KEYWORD: shutdown +####### # # Add the following lines to /etc/rc.conf to enable haproxy: -# haproxy_enable (bool): Set to "NO" by default. -# Set it to "YES" to enable haproxy -# haproxylimits_enable (bool):Set to "NO" by default. -# Set it to yes to run `limits $limits_args` -# just before haproxy starts. -# haproxy_flags (str): Set to "" by default. -# Extra flags passed to start command -# haproxylimits_args (str): Default to "-e -C daemon" -# Arguments of pre-start limits run. # +# haproxy_enable (bool): default: "NO" +# Set to "YES" to enable haproxy +# haproxy_pidfile (str): default: /var/run/${name}.pid +# Set to the full path of the pid file +# haproxy_config (str): default: /usr/local/etc/${name}.conf +# Set to the full path of the config file +# haproxy_flags (str): default: Autogenerated using pidfile and config options +# Set to override with your own options +# +####### +# +# rc.d Script Runtime Options: +# +# start - starts application normally +# stop - (softstop) stops all proxies and exits once all sessions are closed +# forcestop - (immediate) stops all proxies and kills active sessions +# reload - hot-reconfig using "-sf" option (active sessions kept) +# forcereload - hot-reconfig using "-st" option (active sessions killed) +# restart - equiv to "stop" then "start" +# checkconfig - checks configuration file defined in haproxy_config +# +####### + . /etc/rc.subr name="haproxy" rcvar=`set_rcvar` - command="%%PREFIX%%/sbin/haproxy" -pidfile="/var/run/haproxy.pid" -required_files=%%PREFIX%%/etc/haproxy.conf - -[ -z "$haproxy_enable" ] && haproxy_enable="NO" -[ -z "$haproxy_flags" ] && haproxy_flags="-p ${pidfile} -f /usr/local/etc/haproxy.conf" -[ -z "$haproxylimits_enable" ] && haproxylimits_enable="NO" -[ -z "$haproxylimits_args" ] && haproxylimits_args="-e -C daemon" +# Load Configs/Set Defaults load_rc_config $name +: ${haproxy_enable:="NO"} +: ${haproxy_config:="%%PREFIX%%/etc/${name}.conf"} +: ${haproxy_pidfile:="/var/run/${name}.pid"} +: ${haproxy_flags="-q -f ${haproxy_config} -p ${haproxy_pidfile}"} + +# Update the globals +pidfile=${haproxy_pidfile} +required_files=${haproxy_config} + +# Commands: start, stop, restart, reload, checkconfig +extra_commands="reload checkconfig" + +checkconfig_cmd="haproxy_checkconfig" +reload_cmd="haproxy_reload" + +haproxy_reload() +{ + # Check configuration file quietly first + ${command} -q -c -f ${haproxy_config} + if [ $? -ne 0 ]; then + echo "Error found in ${haproxy_config} - not reloading current process!" + return + fi + rc_pid=$(check_pidfile ${haproxy_pidfile} ${command}) + if [ $rc_pid ]; then + if [ $rc_force ]; then + ${command} ${haproxy_flags} -st ${rc_pid} + else + ${command} ${haproxy_flags} -sf ${rc_pid} + fi + else + echo "No process found. Maybe $command isn't running?" + fi +} -checkyesno haproxylimits_enable && \ - start_precmd="eval `/usr/bin/limits ${haproxylimits_args}` 2>/dev/null" +haproxy_checkconfig() +{ + ${command} -c -f ${haproxy_config} +} -sig_gracefulstop=SIGUSR1 +haproxy_prestart() +{ + ${command} -q -c -f ${haproxy_config} + rc_flags=${haproxy_flags} +} -haproxy_gracefulstop() { - echo "Gracefully shutdown haproxy ($rc_pid)" - kill -${sig_gracefulstop} ${rc_pid} - } +haproxy_prestop() +{ + # SIGUSR1 = softstop, SIGTERM = faststop + if [ $rc_force ]; then + sig_stop="SIGTERM" + else + sig_stop="SIGUSR1" + fi +} -reload_cmd="$command $haproxy_flags -sf $(cat $pidfile)" -extra_commands="reload gracefulstop" run_rc_command "$1" |