summaryrefslogtreecommitdiff
path: root/sysutils/p5-Tail-Stat/files/tstatd.in
blob: faf215abcf50ee3f55f5939340ee8a161be14502 (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
#!/bin/sh

# PROVIDE: tstatd
# REQUIRE: DAEMON
#
# Add the following lines to /etc/rc.conf to run tstatd:
#
# tstatd_enable (bool):              Set it to "YES" to enable tstatd.
#                                    Default is "NO".
# tstatd_profiles (strings):         Example - "spam www"
#                                    Default is empty.
# tstatd_profile_flags (string):     Set extra flags. See tstatd(1) for details.
#                                    Default is empty.
# tstatd_profile_listen (string):    Set tstatd listen socket.
#                                    Default is "127.0.0.1:3638".
# tstatd_profile_plugin (string):    Set plugin name. See tstatd(1) for details.
#                                    Default is empty. Required argument.
# tstatd_profile_user (user):        Set user to run tstatd.
#                                    Default is "nobody".
# tstatd_profile_zones (string):     Set tstatd 'zones'. See tstatd(1) for details.
#                                    Default is "nobody". Required argument.

. /etc/rc.subr

name="tstatd"
rcvar=tstatd_enable

load_rc_config ${name}

: ${tstatd_enable="NO"}

command=%%PREFIX%%/bin/tstatd


_profile_exists() {
	for _p in ${tstatd_profiles}; do
		[ "${_p}" = "$1" ] && return 1;
	done
	return 0
}

if [ $# -eq 2 ]; then
	_profile=$2
	_profile_exists $_profile
	_exists=$?
	[ ${_exists} -ne 1 ] && {
		echo "`basename %%PREFIX%%/etc/rc.d/tstatd%%RC_SUBR_SUFFIX%%`: no '$2' in 'tstatd_profiles'"
		exit 1
	};
	echo "-- Profile: $2 --"
	eval _plugin=\${${name}_${_profile}_plugin}
	[ -n "${_plugin}" ] || {
		echo "`basename %%PREFIX%%/etc/rc.d/tstatd%%RC_SUBR_SUFFIX%%`: no 'tstatd_${_profile}_plugin' set"
		exit 2
	};
	eval _zones=\${${name}_${_profile}_zones}
	[ -n "${_zones}" ] || {
		echo "`basename %%PREFIX%%/etc/rc.d/tstatd%%RC_SUBR_SUFFIX%%`: no 'tstatd_${_profile}_zones' set"
		exit 2
	};
	eval _listen=\${${name}_${_profile}_listen:-127.0.0.1:3638}
	eval _user=\${${name}_${_profile}_user:-nobody}
	eval _flags=\${${name}_${_profile}_flags}
	tstatd_flags="${_plugin} -l ${_listen} -u ${_user} -b /var/db/tstatd/${_profile}.db -p /var/run/tstatd/${_profile}.pid ${_flags} ${_zones}"
	pidfile=/var/run/tstatd/${_profile}.pid
elif [ -n "${tstatd_profiles}" ]; then
	_swap=$*; shift; _profiles=$*
	_profiles=${_profiles:-${tstatd_profiles}}
	set -- ${_swap}
	for _profile in ${_profiles}; do
		%%PREFIX%%/etc/rc.d/tstatd%%RC_SUBR_SUFFIX%% $1 ${_profile}
	done
	exit 0
else
	echo "`basename %%PREFIX%%/etc/rc.d/tstatd%%RC_SUBR_SUFFIX%%`: set 'tstatd_profiles' in rc.conf"
	exit 3
fi


run_rc_command "$1"