#!/bin/sh ### BEGIN INIT INFO # Provides: trafficctrl # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Control categories of network traffic # Description: This service provides an HTTP or FastCGI service to # provide a control panel for classifying web traffic. # It does not take any action by itself. # # NOTE: you need to use trafficmon to setup the DB first. ### END INIT INFO NAME="trafficctrl" DAEMON="/usr/sbin/$NAME" RUN=/run CONF=/etc/poorman-ids/sample.js PID="" # 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" # NOTE: this needs to match what $CONF says [ -n "$PID" ] || PID="$RUN/$NAME.pid" mkdir -p "$RUN" ### ACTIONS ### # The main service command CTRL() { start-stop-daemon --pidfile "$PID" --exec "$DAEMON" "$@" } do_start() { echo -n "Starting Traffic Control: " if CTRL --start --oknodo -- -c "$CONF"; then echo "OK" else echo "FAIL" exit 1 fi } do_stop() { echo -n "Stoping Traffic Control: " if CTRL --stop --remove-pidfile; then echo "OK" else echo "FAIL" exit 1 fi } do_status() { echo -n "Traffic Control is: " if CTRL --status; then echo "Up" else echo "Down" exit 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