summaryrefslogtreecommitdiff
path: root/net/balance/files/balance.in
blob: 977bbfc323aa7b657f1e63c31c353f2268f917de (plain) (blame)
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
#!/bin/sh
#
# $FreeBSD: head/net/balance/files/balance.in 340872 2014-01-24 00:14:07Z mat $
#

# PROVIDE: balance
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable balance:
#
#balance_enable="YES"
#balance_hosts="host1"
#balance_host1_flags="-a"
#balance_host1_address="host1.external.example"
#balance_host1_ports="http 8180"
#balance_host1_targets="host1.internal.example"
#
# See balance(8) for flags
#

. /etc/rc.subr

name=balance
rcvar=balance_enable
command=%%PREFIX%%/bin/balance

start_cmd=start_cmd
stop_cmd=stop_cmd
status_cmd=status_cmd

start_cmd()
{
	if [ -x "${command}" ]; then
		for host in ${balance_hosts}; do
			eval ports=\"\${balance_${host}_ports}\"
			eval flags=\"\${balance_${host}_flags}\"
			eval address=\"\${balance_${host}_address}\"
			eval targets=\"\${balance_${host}_targets}\"
			if [ "" != "${address}" ]; then
				flags="${flags} -b ${address}"
			fi
			for port in ${ports}; do
				"${command}" ${flags} ${port} ${targets}
			done
		done
	fi
}

stop_cmd()
{
	if [ -x "${command}" ]; then
		for host in ${balance_hosts}; do
			eval ports=\"\${balance_${host}_ports}\"
			eval address=\"\${balance_${host}_address}\"
			flags=""
			if [ "" != "${address}" ]; then
				flags="-b ${address}"
			else
				address='*'
			fi
			for port in ${ports}; do
				echo "balance at ${address}:${port}"
				"${command}" ${flags} -c kill ${port}
			done
		done
	fi
}

status_cmd()
{
	if [ -x "${command}" ]; then
		for host in ${balance_hosts}; do
			eval ports=\"\${balance_${host}_ports}\"
			eval address=\"\${balance_${host}_address}\"
			flags=""
			if [ "" != "${address}" ]; then
				flags="-b ${address}"
			else
				address='*'
			fi
			for port in ${ports}; do
				echo "balance at ${address}:${port}"
				"${command}" ${flags} -c show ${port}
			done
		done
	fi
}

# set defaults

balance_enable=${balance_enable:-"NO"}

load_rc_config $name
run_rc_command "$1"