File: initscript

package info (click to toggle)
iwatch 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 148 kB
  • sloc: perl: 472; sh: 100; makefile: 41; xml: 28
file content (89 lines) | stat: -rw-r--r-- 2,119 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
### BEGIN INIT INFO
# Provides:          iwatch
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start iwatch, realtime filesystem monitoring program using inotify
### END INIT INFO
set -eu
##############################################################################
IWATCHD=/usr/bin/iwatch
PATH="/sbin:/bin"
DEBIANCONFIG=/etc/default/iwatch
PIDFILE=/var/run/iwatch.pid

test -x $IWATCHD || exit 0

CONFIG_FILE=/etc/iwatch/iwatch.xml
START_DAEMON=true
test -f $DEBIANCONFIG && . $DEBIANCONFIG

. /lib/lsb/init-functions

is_true()
{
  case "${1:-}" in
    [Yy]es|[Yy]|1|[Tt]|[Tt]rue) return 0;;
    *) return 1;
  esac
}
##############################################################################

case "${1:-}" in
    start)
      if [ -f "$PIDFILE" ] ; then
         log_warning_msg "Warning: iwatch daemon already running, doing nothing therefore."
         exit 0
      fi

      if is_true $START_DAEMON; then
         log_daemon_msg "Starting iwatch daemon" "iwatch"
         set +e
         $IWATCHD -f $CONFIG_FILE -p $PIDFILE -d
         RC=$?
         set -e
         log_end_msg $RC
      else
         log_warning_msg "Not starting iwatch daemon as startup is deactivated via /etc/default/iwatch"
      fi
      ;;

    stop)
      if [ -f "$PIDFILE" ] ; then
         log_daemon_msg "Stopping iwatch daemon" "iwatch"
         set +e
         start-stop-daemon -K -p $PIDFILE
         RC=$?
         rm -f $PIDFILE
         set -e
         log_end_msg $RC
      fi
      ;;

    status)
      [ -f "$PIDFILE" ] && PROCESS="$(cat $PIDFILE)" || PROCESS=''
      if [ -n "$PROCESS" ] ; then
         log_success_msg "iwatch daemon with pid $PROCESS is running."
         exit 0
      else
         log_warning_msg "Could not find a running iwatch daemon."
         exit 1
      fi
      ;;

    restart|reload|force-reload)
      $0 stop
      $0 start
      ;;

    *)
      echo "Usage: ${0:-} {start|stop|restart|reload|force-reload|status}" >&2
      exit 1
    ;;
esac

exit 0

# vim: ai expandtab