/rc3.d/S20denyhosts

http://github.com/brinkman83/bashrc · Shell · 93 lines · 71 code · 5 blank · 17 comment · 2 complexity · 70fd8a38fc87e804bd5a114046072a5e MD5 · raw file

  1. #! /bin/sh
  2. #
  3. # Init script for denyhosts
  4. #
  5. # Author: Marco Bertorello <marco@bertorello.ns0.it>.
  6. #
  7. ### BEGIN INIT INFO
  8. # Provides: denyhosts
  9. # Required-Start: $syslog $local_fs $time
  10. # Required-Stop: $syslog $local_fs
  11. # Default-Start: 2 3 4 5
  12. # Default-Stop: 0 1 6
  13. # Short-Description: Start denyhosts and watch .
  14. ### END INIT INFO
  15. # Using LSB funtions:
  16. . /lib/lsb/init-functions
  17. set -e
  18. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  19. DESC="DenyHosts"
  20. NAME=denyhosts
  21. DAEMON=/usr/bin/python
  22. DAEMONCTL=/usr/share/denyhosts/denyhosts_ctl.py
  23. PIDFILE=/var/run/$NAME.pid
  24. SCRIPTNAME=/etc/init.d/$NAME
  25. CONFIG=/etc/denyhosts.conf
  26. FLAGS="--purge --config=$CONFIG"
  27. # Function that starts the daemon/service.
  28. d_start() {
  29. # Gracefully exit if the package has been removed.
  30. test -x $DAEMON || exit 5
  31. test -e $CONFIG || (log_failure_msg "Config file doesn't exists!" && log_end_msg 1)
  32. #check if HOSTS_DENY file exist
  33. HOSTS_DENY=$(grep ^HOSTS_DENY $CONFIG | cut -d = -f 2)
  34. test -e $HOSTS_DENY || touch $HOSTS_DENY
  35. if [ -e $PIDFILE ]; then
  36. pid=$(cat $PIDFILE)
  37. if kill -0 "$pid" > /dev/null; then
  38. log_success_msg "$DESC already running"
  39. return
  40. else
  41. log_success_msg "Removing stale PID file $PIDFILE."
  42. rm -f $PIDFILE
  43. fi
  44. fi
  45. log_daemon_msg "Starting $DESC" "$NAME"
  46. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --startas $DAEMONCTL -- start $FLAGS >/dev/null
  47. log_end_msg $?
  48. }
  49. # Function that stops the daemon/service.
  50. d_stop() {
  51. if [ -e $PIDFILE ]; then
  52. pid=$(cat $PIDFILE)
  53. if kill -0 "$pid" > /dev/null; then
  54. log_daemon_msg "Stopping $DESC" "$NAME"
  55. start-stop-daemon --stop --quiet --pidfile $PIDFILE
  56. log_end_msg $?
  57. else
  58. log_failure_msg "I can't stop $DESC" "Maybe it's NOT running?"
  59. rm -f $PIDFILE
  60. fi
  61. fi
  62. }
  63. # Function that sends a SIGHUP to the daemon/service.
  64. case "$1" in
  65. start)
  66. d_start
  67. ;;
  68. stop)
  69. d_stop
  70. ;;
  71. restart|force-reload)
  72. log_daemon_msg "Restarting $DESC"
  73. d_stop || /bin/true
  74. sleep 1
  75. d_start
  76. log_daemon_msg "Done"
  77. ;;
  78. *)
  79. log_daemon_msg "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  80. exit 3
  81. ;;
  82. esac
  83. exit 0