Empowering makers everywhere!
#!/bin/sh ### BEGIN INIT INFO # Provides: trafficmon # Required-Start: $local_fs # Required-Stop: $local_fs # X-Start-Before: $syslog # X-Stop-After: $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Monitor and record net traffic # Description: This service listens to a pipe for "iptables LOG" and # dnsmasq DNS query messages. It then records information # about internet access into a MySQL DB. Typically these # messages are provided by syslogd. # # NOTE: if this is started after syslogd the pipe might not # be available and syslogd will simply not try to write to # until a restart. ### END INIT INFO NAME="trafficmon" DAEMON="/usr/sbin/$NAME" RUN=/run CONF="" SOCK="" # Pull in config if [ -r "/etc/default/$NAME" ]; then . /etc/default/$NAME fi ### Setup control variables ### # This is where we put PID files and the pipe RUN="$RUN/poorman-ids" PID="$RUN/$NAME.pid" mkdir -p "$RUN" [ -n "$SOCK" ] || SOCK="$RUN/$NAME.sock" ### ACTIONS ### # The main service command CTRL() { start-stop-daemon --pidfile "$PID" --exec "$DAEMON" "$@" } do_start() { echo -n "Starting Traffic Monitor: " if [ -z "$CONF" ]; then echo "NOT CONFIGURED" return 0 fi if CTRL --start --oknodo -- -c "$CONF" -b -i "$PID" -p "$SOCK"; then echo "OK" return 0 #JIC else echo "FAIL" return 1 fi } do_stop() { echo -n "Stoping Traffic Monitor: " if CTRL --stop --remove-pidfile; then echo "OK" return 0 #JIC else echo "FAIL" return 1 fi } do_status() { echo -n "Traffic Monitor is: " if CTRL --status; then echo "Up" return 0 #JIC else echo "Down" return 1 fi } ### Main() case "$1" in start) do_start ;; stop) do_stop ;; restart) do_status && do_stop do_start ;; status) do_status ;; *) echo "$0 {start | stop | restart | status}" ;; esac