/init.d/iwatch

http://github.com/brinkman83/bashrc · Shell · 89 lines · 65 code · 12 blank · 12 comment · 8 complexity · 4a672ec0e94966ccba7022ea747b200e MD5 · raw file

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: iwatch
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Start iwatch, realtime filesystem monitoring program using inotify
  9. ### END INIT INFO
  10. set -eu
  11. ##############################################################################
  12. IWATCHD=/usr/bin/iwatch
  13. PATH="/sbin:/bin"
  14. DEBIANCONFIG=/etc/default/iwatch
  15. PIDFILE=/var/run/iwatch.pid
  16. test -x $IWATCHD || exit 0
  17. CONFIGFILE=/etc/iwatch/iwatch.xml
  18. START_DAEMON=true
  19. test -f $DEBIANCONFIG && . $DEBIANCONFIG
  20. . /lib/lsb/init-functions
  21. is_true()
  22. {
  23. case "${1:-}" in
  24. [Yy]es|[Yy]|1|[Tt]|[Tt]rue) return 0;;
  25. *) return 1;
  26. esac
  27. }
  28. ##############################################################################
  29. case "${1:-}" in
  30. start)
  31. if [ -f "$PIDFILE" ] ; then
  32. log_warning_msg "Warning: iwatch daemon already running, doing nothing therefore."
  33. exit 0
  34. fi
  35. if is_true $START_DAEMON; then
  36. log_daemon_msg "Starting iwatch daemon" "iwatch"
  37. set +e
  38. $IWATCHD -f $CONFIGFILE -p $PIDFILE -d
  39. RC=$?
  40. set -e
  41. log_end_msg $RC
  42. else
  43. log_warning_msg "Not starting iwatch daemon as startup is deactivated via /etc/default/iwatch"
  44. fi
  45. ;;
  46. stop)
  47. if [ -f "$PIDFILE" ] ; then
  48. log_daemon_msg "Stopping iwatch damon" "iwatch"
  49. set +e
  50. start-stop-daemon -K -p $PIDFILE
  51. RC=$?
  52. rm -f $PIDFILE
  53. set -e
  54. log_end_msg $RC
  55. fi
  56. ;;
  57. status)
  58. [ -f "$PIDFILE" ] && PROCESS="$(cat $PIDFILE)" || PROCESS=''
  59. if [ -n "$PROCESS" ] ; then
  60. log_success_msg "iwatch daemon with pid $PROCESS is running."
  61. exit 0
  62. else
  63. log_warning_msg "Could not find a running iwatch daemon."
  64. exit 1
  65. fi
  66. ;;
  67. restart|reload|force-reload)
  68. $0 stop
  69. $0 start
  70. ;;
  71. *)
  72. echo "Usage: ${0:-} {start|stop|restart|reload|force-reload|status}" >&2
  73. exit 1
  74. ;;
  75. esac
  76. exit 0
  77. # vim: ai expandtab