blob: df1fb5a9d6dd7e2b5d39d25f950f7d7b6e0730c6 (
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
|
#!/bin/sh
# PROVIDE: vmagent
# REQUIRE: NETWORK
# BEFORE: DAEMON
. /etc/rc.subr
name="vmagent"
desc="Fast, cost-effective, and scalable time series database"
rcvar="vmagent_enable"
pidfile="/var/run/${name}.pid"
daemon_pidfile="/var/run/${name}-daemon.pid"
logdir="/var/log/${name}"
logfile="${logdir}/vmagent.log"
command="%%PREFIX%%/bin/vmagent"
vmagent_args=${vmagent_args-"--remoteWrite.tmpDataPath=/tmp --promscrape.config=%%PREFIX%%/etc/prometheus/prometheus.yml --remoteWrite.url=http://127.0.0.1:8429/api/v1/write -httpListenAddr=:9429 --memory.allowedPercent=80"}
vmagent_user="%%VICTORIA_USER%%"
load_rc_config ${name}
restart_precmd="checkconfig"
start_precmd="checkconfig"
checkconfig_cmd="checkconfig"
start_cmd="start"
stop_cmd="stop"
status_cmd="status"
extra_commands="checkconfig reload"
checkconfig()
{
local _ret
/usr/bin/su -m ${vmagent_user} -c "${command} ${vmagent_args} -promscrape.config.dryRun" > /dev/null 2>&1
_ret=$?
if [ ${_ret} -ne 0 ]; then
echo "${name} checkconfig failed:"
echo "/usr/bin/su -m ${vmagent_user} -c \"${command} ${vmagent_args} -promscrape.config.dryRun\""
exit ${_ret}
fi
}
start()
{
[ ! -d ${logdir} ] && mkdir -p ${logdir}
touch ${logfile}
chown ${vmagent_user} ${logdir} ${logfile}
/usr/sbin/daemon -u ${vmagent_user} -f -R5 -p ${pidfile} -P ${daemon_pidfile} -o ${logfile} ${command} ${vmagent_args}
}
stop()
{
if [ -f "${daemon_pidfile}" ]; then
pids=$( pgrep -F ${daemon_pidfile} 2>&1 )
_err=$?
[ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${daemon_pidfile}
fi
if [ -f "${pidfile}" ]; then
pids=$( pgrep -F ${pidfile} 2>&1 )
_err=$?
[ ${_err} -eq 0 ] && kill -9 ${pids} && /bin/rm -f ${pidfile}
fi
}
status()
{
if [ -f "${pidfile}" ]; then
pids=$( pgrep -F ${pidfile} 2>&1 )
_err=$?
if [ ${_err} -eq 0 ]; then
echo "${name} is running as pid ${pids}"
exit 0
else
echo "wrong pid: ${pids}"
exit 1
fi
else
echo "no pidfile $pidfile"
exit 1
fi
}
run_rc_command "$1"
|