blob: 5b6216b4580fa14ccab91b2dc168a4c59de1718f (
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
|
#!/bin/sh
# PROVIDE: telegraf
# REQUIRE: DAEMON NETWORKING
# BEFORE: LOGIN
# KEYWORD: shutdown
# Add the following lines to /etc/rc.conf to enable telegrafb:
# telegraf_enable="YES"
#
# telegraf_enable (bool): Set to YES to enable telegraf
# Default: NO
# telegraf_conf (str): telegraf configuration file
# Default: ${PREFIX}/etc/telegraf.conf
# telegraf_confdir (str): telegraf configuration directory
# Default: none
# telegraf_user (str): telegraf daemon user
# Default: %%TELEGRAF_USER%%
# telegraf_group (str): telegraf daemon group
# Default: %%TELEGRAF_GROUP%%
# telegraf_flags (str): Extra flags passed to telegraf
# Default: --quiet
. /etc/rc.subr
PATH=${PATH}:%%LOCALBASE%%/sbin:%%LOCALBASE%%/bin
name="telegraf"
rcvar=telegraf_enable
load_rc_config $name
: ${telegraf_enable:="NO"}
: ${telegraf_user:="%%TELEGRAF_USER%%"}
: ${telegraf_group:="%%TELEGRAF_GROUP%%"}
: ${telegraf_flags:="--quiet"}
: ${telegraf_conf:="%%PREFIX%%/etc/${name}.conf"}
: ${telegraf_confdir:=""}
: ${telegraf_options:="${telegraf_flags} --config=${telegraf_conf}"}
if [ -n "${telegraf_confdir}" ]; then
telegraf_options="${telegraf_options} --config-directory=${telegraf_confdir}"
fi
logfile="%%TELEGRAF_LOGDIR%%/${name}.log"
pidfile="/var/run/${name}.pid"
command=/usr/sbin/daemon
start_precmd="telegraf_prestart"
start_cmd="telegraf_start"
stop_cmd="telegraf_stop"
telegraf_prestart()
{
install -d -o ${telegraf_user} -g ${telegraf_group} -m750 %%TELEGRAF_LOGDIR%%
}
telegraf_start()
{
echo "Starting ${name}"
/usr/sbin/daemon -fcr -P ${pidfile} -u ${telegraf_user} -o ${logfile} \
%%PREFIX%%/bin/${name} ${telegraf_options}
}
telegraf_stop()
{
pid=$(check_pidfile $pidfile $command)
if [ -n "${pid}" ]; then
echo "Stopping ${name} (pid=${pid})"
kill -- -${pid}
wait_for_pids ${pid}
else
echo "${name} isn't running"
fi
}
run_rc_command "$1"
|