"Fossies" - the Fresh Open Source Software Archive

Member "vnstat-2.9/examples/init.d/ubuntu/vnstat" (16 May 2019, 2601 Bytes) of package /linux/misc/vnstat-2.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /bin/sh
    2 ### BEGIN INIT INFO
    3 # Provides:          vnstat
    4 # Required-Start:    $local_fs $remote_fs $network
    5 # Required-Stop:     $local_fs $remote_fs $network
    6 # Default-Start:     2 3 4 5
    7 # Default-Stop:      0 1 6
    8 # Short-Description: lightweight network traffic monitor
    9 ### END INIT INFO
   10 
   11 PATH=/usr/sbin:/usr/bin:/sbin:/bin
   12 DESC="vnStat daemon"
   13 NAME=vnstatd
   14 DAEMON=/usr/sbin/$NAME
   15 DAEMON_ARGS="-d"
   16 PIDFILE=/var/run/vnstat/vnstat.pid
   17 SCRIPTNAME=/etc/init.d/vnstat
   18 
   19 # Exit if the package is not installed
   20 [ -x "$DAEMON" ] || exit 0
   21 
   22 #
   23 # Function that starts the daemon/service
   24 #
   25 do_start()
   26 {
   27     # Return
   28     #   0 if daemon has been started
   29     #   1 if daemon was already running
   30     #   2 if daemon could not be started
   31     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
   32         || return 1
   33     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
   34         $DAEMON_ARGS \
   35         || return 2
   36 }
   37 
   38 #
   39 # Function that stops the daemon/service
   40 #
   41 do_stop()
   42 {
   43     # Return
   44     #   0 if daemon has been stopped
   45     #   1 if daemon was already stopped
   46     #   2 if daemon could not be stopped
   47     #   other if a failure occurred
   48     start-stop-daemon --stop --quiet --retry=TERM/15/KILL/5 --pidfile $PIDFILE --name $NAME
   49     RETVAL="$?"
   50     [ "$RETVAL" = 2 ] && return 2
   51 
   52     rm -f $PIDFILE
   53     return "$RETVAL"
   54 }
   55 
   56 #
   57 # Function that sends a SIGHUP to the daemon/service
   58 #
   59 do_reload() {
   60     start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
   61     return 0
   62 }
   63 
   64 do_status()
   65 {
   66     # Return
   67     #   0 if daemon is stopped
   68     #   1 if daemon is running
   69     start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
   70         || return 1
   71 }
   72 
   73 case "$1" in
   74   start)
   75     echo -n "Starting $DESC: $NAME"
   76     do_start
   77     case "$?" in
   78         0) echo "." ;;
   79         1) echo " already running." ;;
   80         2) echo " start failed." ; exit 1 ;;
   81     esac
   82     ;;
   83   stop)
   84     echo -n "Stopping $DESC: $NAME"
   85     do_stop
   86     case "$?" in
   87         0) echo "." ;;
   88         1) echo " already stopped." ;;
   89         2) echo " stop failed." ; exit 1 ;;
   90     esac
   91     ;;
   92   status)
   93     echo -n "Checking $DESC: "
   94     do_status
   95     case "$?" in
   96         0) echo "stopped." ; exit 3 ;;
   97         1) echo "running." ;;
   98     esac
   99     ;;
  100   reload|force-reload)
  101     echo -n "Reloading $DESC configuration..."
  102     do_reload
  103     echo "done."
  104     ;;
  105   restart)
  106     echo -n "Restarting $DESC: $NAME"
  107     do_stop
  108     case "$?" in
  109       0|1)
  110         do_start
  111         case "$?" in
  112             0) echo "." ;;
  113             1) echo " old process is still running." ;;
  114             *) echo " start failed." ; exit 1 ;;
  115         esac
  116         ;;
  117       *)
  118         echo " stop failed."
  119         exit 1
  120         ;;
  121     esac
  122     ;;
  123   *)
  124     echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2
  125     exit 1
  126     ;;
  127 esac
  128 
  129 exit 0