/init.d/iwatch
http://github.com/brinkman83/bashrc · Shell · 89 lines · 65 code · 12 blank · 12 comment · 8 complexity · 4a672ec0e94966ccba7022ea747b200e MD5 · raw file
- #!/bin/sh
- ### BEGIN INIT INFO
- # Provides: iwatch
- # Required-Start:
- # Required-Stop:
- # 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
- CONFIGFILE=/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 $CONFIGFILE -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 damon" "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