aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/nut_exporter/files/nut_exporter.in
blob: 8e73e9200108db9135dd55281a616141248dd7ab (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
#!/bin/sh

# PROVIDE: nut_exporter
# REQUIRE: LOGIN
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable nut_exporter:
# nut_exporter_enable="YES"
#
# nut_exporter_enable (bool):
#     Set it to YES to enable nut_exporter.
#     Set to NO by default.
# nut_exporter_listen_address (string):
#     IP address and port to listen on.
#     Default is ":9199".
# nut_exporter_user (string):
#     User to run as.
#     Default is "www".
# nut_exporter_metrics_namespace (string):
#     Metrics namespace.
#     Default is "network_ups_tools".
# nut_exporter_tls_cert_file (string):
#     Path to a file that contains the TLS certificate (PEM format).
#     Default is "".
# nut_exporter_tls_key_file (string):
#     Path to a file that contains the TLS private key (PEM format).
#     Default is "".
# nut_exporter_nut_vars_enable (string):
#     A comma-separated list of variable names to monitor.
#     Default is "" (use built-in default from the binary).

. /etc/rc.subr

name=nut_exporter
rcvar=nut_exporter_enable

load_rc_config $name

nut_exporter_enable=${nut_exporter_enable:-"NO"}
nut_exporter_listen_address=${nut_exporter_listen_address:-":9199"}
nut_exporter_user=${nut_exporter_user:-"www"}
nut_exporter_metrics_namespace=${nut_exporter_metrics_namespace:-"network_ups_tools"}
nut_exporter_nut_vars_enable=${nut_exporter_nut_vars_enable:-""}
nut_exporter_tls_cert_file=${nut_exporter_tls_cert_file:-""}
nut_exporter_tls_key_file=${nut_exporter_tls_key_file:-""}

pidfile="/var/run/${name}/${name}.pid"

procname=%%PREFIX%%/bin/nut_exporter
command=/usr/sbin/daemon
command_args="-p ${pidfile} -t ${name} -T ${name} ${procname} \
	--web.listen-address=${nut_exporter_listen_address} \
	--metrics.namespace=${nut_exporter_metrics_namespace} \
	${nut_exporter_nut_vars_enable:+--nut.vars_enable=${nut_exporter_nut_vars_enable}} \
	${nut_exporter_tls_cert_file:+--web.tls.cert_file=${nut_exporter_tls_cert_file}} \
	${nut_exporter_tls_key_file:+--web.tls.key_file=${nut_exporter_tls_key_file}}"

start_precmd=start_precmd
start_precmd()
{
        if [ ! -e "/var/run/${name}" ] ; then
		# Note that ownership of the pidfile determines the user daemon runs under.
                install -d -o ${nut_exporter_user} /var/run/${name};
        fi
}

load_rc_config $name
run_rc_command "$1"