The Poor Man's (or Woman's) Intrusion Detection System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

init 1.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: trafficctrl
  4. # Required-Start: $local_fs
  5. # Required-Stop: $local_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Control categories of network traffic
  9. # Description: This service provides an HTTP or FastCGI service to
  10. # provide a control panel for classifying web traffic.
  11. # It does not take any action by itself.
  12. #
  13. # NOTE: you need to use trafficmon to setup the DB first.
  14. ### END INIT INFO
  15. NAME="trafficctrl"
  16. DAEMON="/usr/sbin/$NAME"
  17. RUN=/run
  18. CONF=""
  19. PID=""
  20. GROUP=""
  21. # Pull in config
  22. if [ -r "/etc/default/$NAME" ]; then
  23. . /etc/default/$NAME
  24. fi
  25. ### Setup control variables ###
  26. # This is where we put PID files and the pipe
  27. RUN="$RUN/poorman-ids"
  28. # NOTE: this needs to match what $CONF says
  29. [ -n "$PID" ] || PID="$RUN/$NAME.pid"
  30. mkdir -p "$RUN"
  31. [ -z "$GROUP" ] || GROUP="-g $GROUP"
  32. ### ACTIONS ###
  33. # The main service command
  34. CTRL() {
  35. start-stop-daemon --pidfile "$PID" --exec "$DAEMON" "$@"
  36. }
  37. do_start() {
  38. echo -n "Starting Traffic Control: "
  39. if [ -z "$CONF" ]; then
  40. echo "NOT CONFIGURED"
  41. return 0
  42. fi
  43. if CTRL --start --oknodo --umask 007 $GROUP -- -c "$CONF"; then
  44. echo "OK"
  45. return 0 #JIC
  46. else
  47. echo "FAIL"
  48. return 1
  49. fi
  50. }
  51. do_stop() {
  52. echo -n "Stoping Traffic Control: "
  53. if CTRL --stop --remove-pidfile; then
  54. echo "OK"
  55. return 0 #JIC
  56. else
  57. echo "FAIL"
  58. return 1
  59. fi
  60. }
  61. do_status() {
  62. echo -n "Traffic Control is: "
  63. if CTRL --status; then
  64. echo "Up"
  65. return 0 #JIC
  66. else
  67. echo "Down"
  68. return 1
  69. fi
  70. }
  71. ### Main()
  72. case "$1" in
  73. start)
  74. do_start
  75. ;;
  76. stop)
  77. do_stop
  78. ;;
  79. restart)
  80. do_status && do_stop
  81. do_start
  82. ;;
  83. status)
  84. do_status
  85. ;;
  86. *)
  87. echo "$0 {start | stop | restart | status}"
  88. ;;
  89. esac