summaryrefslogtreecommitdiff
path: root/net-analyzer/mrtg/files/mrtg.rc
blob: 0ff5d0783f38b15e13cbe7823f46ee167c13fe78 (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
#!/sbin/openrc-run
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
    need net
    
    # if monitoring snmp variables on this machine:
    # use net-snmpd
}
 
checkconfig() {
    if [ ! -f ${MRTG_CONF} ] ; then
		eerror "Please create ${MRTG_CONF} (try man cfgmaker)"
		return 1
	fi

	mrtg --check ${MRTG_CONF}
	return $?
}

start() {
	# mrtg will not run if LANG=*utf8
	# use grep instead of bash regexp for bug #159786
	[ "$(echo $LANG|grep -E '((^[A-Za-z0-9\_\@\-]+\.)|(^))([uU][tT][fF]-?8)$')" ] \
	&& LANG='C'

	checkconfig || return $?

	# enable logging?
	[ -n "${MRTG_LOG}" ] && \
		MRTG_OPTS="${MRTG_OPTS} --logging ${MRTG_LOG}"
	
	# run as a different user?
	[ -n "${MRTG_USER}" ] && \
		MRTG_OPTS="${MRTG_OPTS} --user ${MRTG_USER}"

	# run as a different group?
	[ -n "${MRTG_GROUP}" ] && \
		MRTG_OPTS="${MRTG_OPTS} --group ${MRTG_GROUP}"

	ebegin "Starting mrtg"
	start-stop-daemon --start --quiet --pidfile ${MRTG_PID} --name mrtg\
		--exec /usr/bin/mrtg -- --daemon --pid-file=${MRTG_PID} \
		${MRTG_OPTS} ${MRTG_CONF} >/dev/null
	eend $? "Failed to start mrtg"
}

stop() {
	ebegin "Stopping mrtg"
	start-stop-daemon --stop --quiet --pidfile ${MRTG_PID}
	eend $? "Failed to stop mrtg"
}