blob: ab87b8ef6f6ccc36a7dd8389bec9dba3d66e29ae (
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#!/bin/sh
#
# PROVIDE: cbsd_statsd_jail
# REQUIRE: LOGIN FILESYSTEMS cbsdd
# KEYWORD: shutdown
#
# cbsd_statsd_jail_enable="YES"
#
. /etc/rc.subr
name=cbsd_statsd_jail
rcvar=cbsd_statsd_jail_enable
load_rc_config $name
# Set defaults
: ${cbsd_statsd_jail_enable:="NO"}
export workdir="${cbsd_workdir}"
globalconf=${cbsd_globalconf:-"%%PREFIX%%/cbsd/cbsd.conf"}
start_cmd=${name}_start
stop_cmd=${name}_stop
restart_cmd=${name}_restart
extra_commands="restart"
command="%%PREFIX%%/cbsd/tools/racct-jail-statsd"
pidfile="${cbsd_workdir}/var/run/${name}.pid"
daemon_pidfile="${cbsd_workdir}/var/run/${name}-daemon.pid"
daemon_logdir="/var/log/${name}"
workdir_normalize=$( echo ${cbsd_workdir} | /usr/bin/tr "/" "_" )
daemon_logfile="${daemon_logdir}/cbsd-statsd-jail${workdir_normalize}.log"
command_args="&"
if [ ! -f ${globalconf} ]; then
echo "cbsd: no such ${globalconf}";
exit 1
fi
if [ ! -f ${subr} ]; then
echo "cbsd: no such ${subr}";
exit 1
fi
. ${globalconf}
. ${subrdir}/nc.subr
cbsd_statsd_jail_stop()
{
local _pids
if [ -f "${daemon_pidfile}" ]; then
_pids=$( pgrep -F ${daemon_pidfile} 2>&1 )
_err=$?
/bin/rm -f ${daemon_pidfile}
if [ ${_err} -eq 0 ]; then
kill -9 ${_pids}
else
echo "pgrep: ${_pids}"
fi
fi
if [ -f "${pidfile}" ]; then
_pids=$( pgrep -F ${pidfile} 2>&1 )
_err=$?
/bin/rm -f ${pidfile}
if [ ${_err} -eq 0 ]; then
kill -9 ${_pids}
else
echo "pgrep: ${_pids}"
fi
fi
return 0
}
cbsd_statsd_jail_start()
{
local args= racct_enabled= pool_name= prometheus_listen4= prometheus_listen6= prometheus_port=
# RACCT enabled?
racct_enabled=$( sysctl -qn kern.racct.enable )
[ $? -ne 0 ] && err 1 "cbsd-statsd-jail: RACCT not enabled"
[ "${racct_enabled}" != "1" ] && err 1 "cbsd-statsd-jail: RACCT not enabled"
readconf racct-jail-statsd.conf
[ -n "${log_file}" ] && args="${args} --log_file=${log_file}"
[ -n "${log_level}" ] && args="${args} --log_level=${log_level}"
[ -n "${loop_interval}" ] && args="${args} --loop_interval=${loop_interval}"
[ -n "${save_loop_count}" ] && args="${args} --save_loop_count=${save_loop_count}"
[ -z "${pool_name}" ] && pool_name=$( hostname )
[ -n "${pool_name}" ] && args="${args} --pool_name=${pool_name}"
[ -n "${prometheus_listen4}" ] && args="${args} --prometheus_listen4=${prometheus_listen4}"
[ -n "${prometheus_listen6}" ] && args="${args} --prometheus_listen6=${prometheus_listen6}"
[ -z "${prometheus_port}" ] && prometheus_port=9999
[ -n "${prometheus_port}" ] && args="${args} --prometheus_port=${prometheus_port}"
case "${prometheus_exporter_enable}" in
[Yy][Ee][Ss])
args="${args} --prometheus_exporter=1"
;;
[No][Oo])
args="${args} --prometheus_exporter=0"
;;
esac
case "${beanstald_enable}" in
[Yy][Ee][Ss])
args="${args} --save_beanstalkd=1"
;;
[No][Oo])
args="${args} --save_beanstalkd=0"
;;
esac
case "${sqlite3_enable}" in
[Yy][Ee][Ss])
args="${args} --save_sqlite=1"
;;
[No][Oo])
args="${args} --save_sqlite=0"
;;
esac
[ ! -d ${daemon_logdir} ] && mkdir -p ${daemon_logdir}
touch ${daemon_logfile}
/usr/sbin/daemon -f -R5 -P ${daemon_pidfile} -o ${daemon_logfile} /usr/bin/env workdir=${cbsd_workdir} ${command} ${args}
}
cbsd_statsd_jail_restart()
{
cbsd_statsd_jail_stop
cbsd_statsd_jail_start
}
run_rc_command "$1"
|