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
|
#!/bin/sh
#
# init.d script for BandwidthD
# Andreas Henriksson <andreas@fatal.se>
#
#
DAEMON=/usr/sbin/bandwidthd
WORKDIR=/var/lib/bandwidthd
CONFFILE=/etc/bandwidthd/bandwidthd.conf
NAME=bandwidthd
DESC=BandwidthD
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
checkconfig ()
{
# abort if there's no configuration file at all.
if [ ! -f "$CONFFILE" ]; then
echo "$DESC: No configuration file found, not starting."
exit 0
fi
# abort if we detect an unconfigured bandwidthd-pgsql config.
CONFERR=$(grep -c1 "pgsql_connect_string \"user = someuser dbname = mydb host = localhost\"" $CONFFILE)
if [ "$CONFERR" != "0" ]; then
echo ""
echo "ATTENTION!"
echo "You have to manually add the postgresql-user, database and tables."
echo "(Schema available at /usr/share/doc/bandwidthd-pgsql/schema.postgresql)"
echo "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."
echo ""
exit 0
fi
# abort if the config doesn't have a device set up.
CONFERR=$(grep -c1 "^[^#].*d*ev " $CONFFILE)
if [ "$CONFERR" = "0" ]; then
echo "Skipping $DESC: Please edit $CONFFILE."
exit 0
fi
}
startd ()
{
echo -n "Starting $DESC: "
cd $WORKDIR && start-stop-daemon --start --quiet \
--pidfile $PIDFILE \
--chdir $WORKDIR \
--exec $DAEMON -- $DAEMON_OPTS
if [ "$?" != "0" ]; then
echo "failed."
else
echo "$NAME."
fi
}
stopd ()
{
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --signal TERM \
--pidfile $PIDFILE --exec $DAEMON
if [ "$?" != "0" ]; then
echo "failed."
else
echo "$NAME."
fi
}
restartd ()
{
stopd
sleep 1
startd
}
rotatelogs ()
{
echo -n "Rotating logs for $DESC: "
start-stop-daemon --stop --quiet --signal HUP \
--pidfile $PIDFILE --exec $DAEMON
if [ "$?" != "0" ]; then
echo "failed."
else
echo "$NAME."
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
|