aboutsummaryrefslogtreecommitdiff
path: root/network/vnstat/rc.vnstat
diff options
context:
space:
mode:
authorMichiel van Wessem <michiel@slackbuilds.org>2010-05-12 17:44:25 +0200
committerDavid Somero <xgizzmo@slackbuilds.org>2010-05-12 17:44:25 +0200
commitb83a67ebf626bbe4bf6f9558db2ce44881e340ce (patch)
tree7a9ab36100191f022d815ba75cc7975714f7c954 /network/vnstat/rc.vnstat
parent1ecd34752cc70faa167f0b40483b709765425656 (diff)
network/vnstat: Updated for version 1.7
Diffstat (limited to 'network/vnstat/rc.vnstat')
-rw-r--r--network/vnstat/rc.vnstat73
1 files changed, 73 insertions, 0 deletions
diff --git a/network/vnstat/rc.vnstat b/network/vnstat/rc.vnstat
new file mode 100644
index 000000000000..bb9e948c02b7
--- /dev/null
+++ b/network/vnstat/rc.vnstat
@@ -0,0 +1,73 @@
+#!/bin/sh
+#
+# /etc/rc.d/rc.vnstat - Start/stop/restart the vndstat daemon.
+# To make vnstat start automatically at boot, make this
+# file executable: chmod 0755 /etc/rc.d/rc.vnstat
+#
+
+CONFIGFILE="/etc/vnstat.conf"
+INTERFACE="eth0"
+
+DBASEDIR="/var/lib/vnstat/"
+PIDFILE="/var/run/vnstat.pid"
+
+vnstat_start() {
+ if [ -e "$PIDFILE" ]; then
+ echo "vnstatd is already running under PID: $PIDFILE"
+ elif [ -x /usr/sbin/vnstatd -a -r $CONFIGFILE ]; then
+ if [ ! -e "$DBASEDIR/$INTERFACE" ]; then
+ # Sadly vnstat throws everything out over STDOUT instead of
+ # using STERR for warnings and such.
+ /usr/bin/vnstat -u -i "$INTERFACE" 1> /dev/null
+ sleep 2
+ fi
+ echo "Starting the vnstat daemon for interface $INTERFACE..."
+ /usr/sbin/vnstatd --config $CONFIGFILE --daemon
+ fi
+}
+
+vnstat_stop() {
+ # There be demons here. I am sure we can get the pid from /var/run/
+ # for a much cleaner shutdown.
+ echo -n "Stopping the vnstat Daemon..."
+ if [ -r $PIDFILE ]; then
+ kill $(cat $PIDFILE)
+ sleep 2
+ if [ -e "$PIDFILE" ]; then
+ rm $PIDFILE
+ fi
+ echo "Done"
+ else
+ killall vnstatd
+ echo "Done"
+ fi
+}
+
+vnstat_restart() {
+ echo "restarting the vnstart daemon..."
+ vnstat_stop
+ sleep 2
+ vnstat_start
+}
+
+
+case "$1" in
+ 'start')
+ vnstat_start
+ ;;
+ 'stop')
+ vnstat_stop
+ ;;
+ 'restart','reload')
+ vnstat_restart
+ ;;
+ 'status')
+ vnstat_status
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart|reload|status}"
+ exit 1
+ ;;
+esac
+
+