blob: 8127c9adffe6bb863562a9e93109768e5ad071f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#!/bin/sh
# PROVIDE: haproxy
# REQUIRE: DAEMON
# 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
# 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"
# 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
}
haproxy_checkconfig()
{
${command} -c -f ${haproxy_config}
}
haproxy_prestart()
{
${command} -q -c -f ${haproxy_config}
rc_flags=${haproxy_flags}
}
haproxy_prestop()
{
# SIGUSR1 = softstop, SIGTERM = faststop
if [ $rc_force ]; then
sig_stop="SIGTERM"
else
sig_stop="SIGUSR1"
fi
}
run_rc_command "$1"
|