PageRenderTime 124ms CodeModel.GetById 120ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/rc2.d/S20iwatch

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