File: mrtg.init

package info (click to toggle)
mrtg 2.17.10-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,216 kB
  • sloc: perl: 25,746; ansic: 4,568; sh: 1,518; php: 227; awk: 225; makefile: 196; csh: 49; exp: 16
file content (102 lines) | stat: -rw-r--r-- 2,115 bytes parent folder | download | duplicates (6)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
# Start/stop the MRTG
# Original author:    Stefan SF <stefan@sf-net.com> (for Fedora Project)
# Updates for Debian: Joao Eriberto Mota Filho <eriberto@debian.org>
#
### BEGIN INIT INFO
# Provides: mrtg
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the The Multi Router Traffic Grapher
# Description: The Multi Router Traffic Grapher is a tool primarily used to
#              monitor the traffic load on network links (typically by using
#              SNMP). MRTG generates HTML pages containing PNG images which
#              provide a LIVE visual representation of this traffic. MRTG
#              typically produces daily, weekly, monthly, and yearly graphs.
### END INIT INFO

# source function library
. /lib/lsb/init-functions

MRTG="/usr/bin/mrtg"
USERMRTG="mrtg"
CONFIG="/etc/mrtg/mrtg.cfg"
PIDFILE="/run/mrtg/mrtg.pid"
OPTIONS="--daemon --fhs --user=${USERMRTG}"

RETVAL=0

start() {
	if [ ! -e $PIDFILE ]
	then
	    WORKDIR=$(cat ${CONFIG} | grep -i WorkDir | cut -d: -f2 | tr -d " ")
	    if [ -z ${WORKDIR} ]
	    then
		echo "ERROR: WorkDir not defined in config file"
		exit 1
	    fi
	    if [ ! -d ${WORKDIR} ]
	    then
		echo "ERROR: no such directory: ${WORKDIR}"
		exit 1
	    fi
	    OWNERWORKDIR=$(stat -c '%U' ${WORKDIR})
	    if [ ${OWNERWORKDIR} != ${USERMRTG} ]
	    then
		echo "ERROR: ${WORKDIR} is not owned by ${USERMRTG}"
		exit 1
	    fi
	    echo "Starting MRTG"
	    LANG=C ${MRTG} ${OPTIONS} ${CONFIG}
	    RETVAL=$?
	else
	    echo "MRTG is already running"
	    RETVAL=$?
	fi
}

stop() {
	if [  -e $PIDFILE ]
	then
	    echo "Stopping MRTG"
	    kill `cat ${PIDFILE}`
	    RETVAL=$?
	else
	    echo "MRTG is not running"
	    RETVAL=$?
	fi
}

restart() {
	stop
	sleep 1
	start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|force-reload)
	restart
	;;
  status)
	if [ -e $PIDFILE ]; then
		echo "MRTG is enabled"
		RETVAL=0
	else
		echo "MRTG is disabled"
		RETVAL=3
	fi
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|force-reload}"
	exit 1
esac

exit $RETVAL