softflowd.init 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: softflowd
  4. # Required-Start: $network $remote_fs $syslog
  5. # Required-Stop: $network $remote_fs $syslog
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Flow-based network traffic analyser.
  9. ### END INIT INFO
  10. # Author: Christoph Biedl <debian.packages.hhqj@manchmal.in-ulm.de>
  11. # Based on /etc/init.d/skeleton, written by
  12. # Miquel van Smoorenburg <miquels@cistron.nl>,
  13. # modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DAEMON=/usr/sbin/softflowd
  16. NAME=softflowd
  17. DESC="Flow-based network traffic analyser"
  18. DEFAULT=/etc/default/$NAME
  19. PIDFILE=/var/run/$NAME.pid
  20. PRIVDROP_CHROOT_DIR=/var/run/softflowd/chroot
  21. test -x "$DAEMON" || exit 0
  22. # Include softflowd defaults if available
  23. INTERFACE=
  24. OPTIONS=
  25. [ -r "$DEFAULT" ] && . "$DEFAULT"
  26. # Load the VERBOSE setting and other rcS variables
  27. . /lib/init/vars.sh
  28. # Define LSB log_* functions.
  29. . /lib/lsb/init-functions
  30. case "$1" in
  31. start|restart|force-reload)
  32. if [ -z "$INTERFACE" ] ; then
  33. log_daemon_msg "NOT starting $DESC" "$NAME"
  34. log_action_msg "\nEdit $DEFAULT and define the INTERFACE variable"
  35. log_end_msg 1
  36. exit 0
  37. fi
  38. ;;
  39. esac
  40. [ -d "$PRIVDROP_CHROOT_DIR" ] || mkdir -p "$PRIVDROP_CHROOT_DIR"
  41. #
  42. # Function that starts the daemon/service
  43. #
  44. do_start()
  45. {
  46. # Return
  47. # 0 if daemon has been started
  48. # 1 if daemon was already running
  49. # 2 if daemon could not be started
  50. start-stop-daemon --start --quiet --pidfile $PIDFILE \
  51. --exec $DAEMON --test > /dev/null || \
  52. return 1
  53. start-stop-daemon --start --quiet --pidfile $PIDFILE \
  54. --exec $DAEMON -- -i "$INTERFACE" $OPTIONS || \
  55. return 2
  56. }
  57. #
  58. # Function that stops the daemon/service
  59. #
  60. do_stop()
  61. {
  62. # Return
  63. # 0 if daemon has been stopped
  64. # 1 if daemon was already stopped
  65. # 2 if daemon could not be stopped
  66. # other if a failure occurred
  67. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
  68. --pidfile $PIDFILE --name $NAME
  69. RETVAL="$?"
  70. [ "$RETVAL" = 2 ] && return 2
  71. # Wait for children to finish too if this is a daemon that forks
  72. # and if the daemon is only ever run from this initscript.
  73. # If the above conditions are not satisfied then add some other code
  74. # that waits for the process to drop all resources that could be
  75. # needed by services started subsequently. A last resort is to
  76. # sleep for some time.
  77. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
  78. --exec $DAEMON
  79. [ "$?" = 2 ] && return 2
  80. # Many daemons don't delete their pidfiles when they exit.
  81. rm -f $PIDFILE
  82. return "$RETVAL"
  83. }
  84. case "$1" in
  85. start)
  86. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  87. do_start
  88. case "$?" in
  89. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  90. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  91. esac
  92. ;;
  93. stop)
  94. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  95. do_stop
  96. case "$?" in
  97. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  98. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  99. esac
  100. ;;
  101. status)
  102. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  103. ;;
  104. restart|force-reload)
  105. log_daemon_msg "Restarting $DESC" "$NAME"
  106. do_stop
  107. case "$?" in
  108. 0|1)
  109. do_start
  110. case "$?" in
  111. 0) log_end_msg 0 ;;
  112. 1) log_end_msg 1 ;; # Old process is still running
  113. *) log_end_msg 1 ;; # Failed to start
  114. esac
  115. ;;
  116. *)
  117. # Failed to stop
  118. log_end_msg 1
  119. ;;
  120. esac
  121. ;;
  122. *)
  123. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  124. exit 3
  125. ;;
  126. esac
  127. :