diff options
author | demon <demon@FreeBSD.org> | 2014-11-27 23:37:21 +0800 |
---|---|---|
committer | demon <demon@FreeBSD.org> | 2014-11-27 23:37:21 +0800 |
commit | f711f5b219d4689936b52c7e78c2d3e7ffe89855 (patch) | |
tree | 07a5f45396fe140277f2b8d527c4348d841c42b8 /net | |
parent | 1e99883bc093b1c4c7e3dc3d2bb6ae8b9b8c4e8e (diff) | |
download | freebsd-ports-gnome-f711f5b219d4689936b52c7e78c2d3e7ffe89855.tar.gz freebsd-ports-gnome-f711f5b219d4689936b52c7e78c2d3e7ffe89855.tar.zst freebsd-ports-gnome-f711f5b219d4689936b52c7e78c2d3e7ffe89855.zip |
Add support for profiles (to start several haproxy instances each with it's own
config).
Diffstat (limited to 'net')
-rw-r--r-- | net/haproxy/Makefile | 1 | ||||
-rw-r--r-- | net/haproxy/files/haproxy.in | 87 |
2 files changed, 54 insertions, 34 deletions
diff --git a/net/haproxy/Makefile b/net/haproxy/Makefile index c52ac8fc2b28..b8a1f4814b22 100644 --- a/net/haproxy/Makefile +++ b/net/haproxy/Makefile @@ -3,6 +3,7 @@ PORTNAME= haproxy PORTVERSION= 1.5.9 +PORTREVISION= 1 CATEGORIES= net www MASTER_SITES= http://www.haproxy.org/download/1.5/src/ diff --git a/net/haproxy/files/haproxy.in b/net/haproxy/files/haproxy.in index 1f1c5dd3fa4e..48a5ae7604c6 100644 --- a/net/haproxy/files/haproxy.in +++ b/net/haproxy/files/haproxy.in @@ -7,73 +7,92 @@ # REQUIRE: DAEMON LOGIN # KEYWORD: shutdown -####### # # Add the following lines to /etc/rc.conf to enable haproxy: # # haproxy_enable (bool): default: "NO" # Set to "YES" to enable haproxy -# haproxy_pidfile (str): default: /var/run/${name}.pid +# haproxy_pidfile (str): default: /var/run/haproxy.pid # Set to the full path of the pid file -# haproxy_config (str): default: /usr/local/etc/${name}.conf +# haproxy_config (str): default: %%PREFIX%%/etc/haproxy.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" -# configtest - checks configuration file defined in haproxy_config -# -####### +# haproxy_profiles (str): default: empty +# Set to space-separated list of profiles: for each profile separate haproxy +# process will be spawned, with haproxy-${profile}.conf config file. +# You can override default pidfile and config file for each profile with +# haproxy_${profile}_config and haproxy_${profile}_pidfile. . /etc/rc.subr name="haproxy" rcvar=haproxy_enable command="%%PREFIX%%/sbin/haproxy" +extra_commands="reload configtest" +reload_cmd="haproxy_reload" -# Load Configs/Set Defaults -load_rc_config $name : ${haproxy_enable:="NO"} -pidfile=${haproxy_pidfile:-"/var/run/haproxy.pid"} : ${haproxy_config:="%%PREFIX%%/etc/${name}.conf"} -: ${haproxy_flags="-q -f ${haproxy_config} -p ${pidfile}"} -procname=${command} +pidfile=${haproxy_pidfile:-"/var/run/haproxy.pid"} -# Update the globals -required_files=$haproxy_config +if [ -z "$rc_force" ]; then + sig_stop="USR1" +fi -# Commands: start, stop, restart, reload, configtest -extra_commands="reload configtest" +load_rc_config $name + +is_valid_profile() { + local profile + for profile in $haproxy_profiles; do + if [ "$profile" = "$1" ]; then + return 0 + fi + done + return 1 +} +if [ -n "$2" ]; then + profile=$2 + if ! is_valid_profile $profile; then + echo "$0: no such profile ($profile) defined in ${name}_profiles." + exit 1 + fi + eval haproxy_config="\${haproxy_${profile}_config:-%%PREFIX%%/etc/haproxy-${profile}.conf}" + eval pidfile="\${haproxy_${profile}_pidfile:-/var/run/haproxy-${profile}.pid}" +else + if [ "x${haproxy_profiles}" != "x" -a "x$1" != "x" ]; then + for profile in ${haproxy_profiles}; do + echo "===> ${name} profile: ${profile}" + %%PREFIX%%/etc/rc.d/haproxy $1 ${profile} + retcode="$?" + if [ ${retcode} -ne 0 ]; then + failed="${profile} (${retcode}) ${failed:-}" + else + success="${profile} ${success:-}" + fi + done + exit 0 + fi +fi + +: ${haproxy_flags:="-q -f ${haproxy_config} -p ${pidfile}"} configtest_cmd="$command -c -f $haproxy_config" start_precmd="$command -q -c -f $haproxy_config" -reload_cmd="haproxy_reload" - -# For stopping, SIGUSR1 = softstop, SIGTERM = faststop -sig_stop=${rc_force:-USR1} +required_files=$haproxy_config haproxy_reload() { - # Check configuration file quietly first ${command} -q -c -f ${haproxy_config} if [ $? -ne 0 ]; then err 1 "Error found in ${haproxy_config} - not reloading current process!" fi rc_pid=$(check_pidfile ${pidfile} ${command}) if [ $rc_pid ]; then - if [ $rc_force ]; then - ${command} ${haproxy_flags} -st $(cat ${pidfile}) - else + if [ -z "$rc_force" ]; then ${command} ${haproxy_flags} -sf $(cat ${pidfile}) + else + ${command} ${haproxy_flags} -st $(cat ${pidfile}) fi else _run_rc_notrunning |