blob: 09ab801da009184e80f49dffafcf5079ffce4928 (
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: ipacctd
# REQUIRE: NETWORKING SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable ipacctd:
#
#ipacctd_enable="YES"
#
# Also additional flags can be specified:
#
#ipacctd_flags="-v"
#
# See ipacctd(8) for flags.
#
# Enumerate all accounted interfaces in "ipacctd_rules":
#
#ipacctd_rules="xl0"
#
# ...and add related required "ipacctd_rule_*_flags"
# and optional "ipacctd_rule_*_pid" (equal to "/var/run/ipacctd.*" by default)
#
#ipacctd_rule_xl0_flags="-p 666"
#ipacctd_rule_xl0_pid="/var/run/ipacctd.xl0"
. %%RC_SUBR%%
name="ipacctd"
rcvar=`set_rcvar`
command="%%PREFIX%%/sbin/ipacctd"
start_cmd="start_cmd"
stop_cmd="stop_cmd"
poll_cmd="poll_cmd"
status_cmd="status_cmd"
start_cmd()
{
for rule in ${ipacctd_rules}; do
debug "start ipacctd rule ${rule}"
local rule_flags
eval rule_flags=\$ipacctd_rule_${rule}_flags
if [ -z "$rule_flags" ]; then
echo " you must define flags for ipacctd rule '${rule}'"
exit 1
fi
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -n "$rc_pid" ]; then
echo "${name} with rule=$rule already running? (pid=$rc_pid)."
exit 1
fi
${command} ${ipacctd_flags} ${rule_flags} -r ${pidfile}
done
}
stop_cmd()
{
for rule in ${ipacctd_rules}; do
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -z "$rc_pid" ]; then
if [ -n "$pidfile" ]; then
echo "${name} with rule=$rule not running? (check $pidfile)."
else
echo "${name} with rule=$rule not running?"
fi
exit 1
fi
echo "Stopping ${name} rule=${rule}."
kill -${sig_stop:-TERM} $rc_pid
wait_for_pids $rc_pid
done
}
poll_cmd()
{
for rule in ${ipacctd_rules}; do
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -n "$rc_pid" ]; then
wait_for_pids $rc_pid
fi
done
}
status_cmd()
{
for rule in ${ipacctd_rules}; do
eval pidfile=\${ipacctd_rule_${rule}_pid:-"/var/run/ipacctd.${rule}"}
rc_pid=$(check_pidfile $pidfile $command)
if [ -n "$rc_pid" ]; then
echo "${name} rule=${rule} is running as pid $rc_pid."
else
echo "${name} rule=${rule} is not running."
fi
done
}
load_rc_config $name
: ${ipacctd_enable="NO"}
: ${ipacctd_rules=""}
: ${ipacctd_flags=""}
run_rc_command "$1"
|