File: bandwidthd.init

package info (click to toggle)
bandwidthd 2.0.1%2Bcvs20090917-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,316 kB
  • sloc: sh: 3,010; ansic: 2,752; php: 1,263; yacc: 216; makefile: 152; lex: 36; sql: 27
file content (128 lines) | stat: -rw-r--r-- 2,999 bytes parent folder | download | duplicates (8)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/sh
#
#		init.d script for BandwidthD
#		Andreas Henriksson <andreas@fatal.se>
#
### BEGIN INIT INFO
# Provides:          bandwidthd
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts and stops the BandwidthD daemon.
# Description:       Script to start and stop the BandwidthD daemon
#                    which captures traffic and generates graphs over
#                    bandwidthd usage.
### END INIT INFO

NAME=bandwidthd
DESC=BandwidthD
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/bandwidthd
PIDFILE=/var/run/$NAME.pid
WORKDIR=/var/lib/bandwidthd
CONFFILE=/etc/bandwidthd/bandwidthd.conf

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

checkconfig ()
{
	# abort if there's no configuration file at all.
	if [ ! -f "$CONFFILE" ]; then
		log_failure_msg "$DESC: No configuration file found, not starting."
		exit 0
	fi

	# abort if we detect an unconfigured bandwidthd-pgsql config.
	CONFERR=$(grep "pgsql_connect_string \"user = someuser dbname = mydb host = localhost\"" $CONFFILE | grep -c "^[^#]")
	if [ "$CONFERR" != "0" ]; then

		log_failure_msg "ATTENTION!"
		log_failure_msg "You have to manually add the postgresql-user, database and tables."
		log_failure_msg "You also have to edit /etc/bandwidthd/bandwidthd.conf to specify which database the sensor should log to. If you want to run the web-interface on this computer you also need to edit /var/lib/bandwidthd/htdocs/config.conf to specify the postgresql-connection settings there and create a symlink from your webroot to the htdocs directory."

		exit 0
	fi
	
	# abort if the config doesn't have a device set up.
	CONFERR=$(grep -c1 "^[^#].*d*ev " $CONFFILE)
	if [ "$CONFERR" = "0" ]; then
		log_failure_msg "Skipping $DESC: No devices configured. Please edit $CONFFILE."
		exit 0
	fi
}

startd ()
{
	log_daemon_msg "Starting $DESC" "$NAME"
	cd $WORKDIR && start-stop-daemon --start --quiet \
		--pidfile $PIDFILE \
		--chdir $WORKDIR \
		--exec $DAEMON -- $DAEMON_OPTS
	if [ $? = 0 ]; then
		log_end_msg 0
	else
		log_end_msg 1
	fi
}

stopd ()
{
	log_daemon_msg "Stopping $DESC" "$NAME"
	#start-stop-daemon --stop --quiet --signal TERM \
	#	--pidfile $PIDFILE --exec $DAEMON
	killproc -p $PIDFILE $DAEMON SIGTERM
	if [ $? = 0 ]; then
		log_end_msg 0
	else
		log_end_msg 1
	fi
}

restartd ()
{
	stopd
	sleep 1
	startd
}

rotatelogs ()
{
	log_daemon_msg "Rotating logs for $DESC" "$NAME"
	start-stop-daemon --stop --quiet --signal HUP \
		--pidfile $PIDFILE --exec $DAEMON
	if [ $? = 0 ]; then
		log_end_msg 0
	else
		log_end_msg 1
	fi
}


case "$1" in
	start)
		checkconfig
		startd
	;;
	stop)
		stopd
	;;
	rotate)
		rotatelogs
	;;
	restart|force-reload)
		checkconfig
		restartd
	;;
	*)
		N=/etc/init.d/$NAME
		echo "Usage: $N {start|stop|restart|rotate|force-reload}" >&2
		exit 1
	;;
esac

exit 0