Blob Blame History Raw
#!/bin/sh
#
# fsniper      Monitors directories for new files and invokes scripts on them
#
# chkconfig: - 55 65
# description: fsniper is a tool that monitors a given set of directories for \
#              new files. Then, based on the new file's type or name, it \
#              invokes a script to be run (any executable via the shell) on \
#              that file. Common uses include making a single drop directory \
#              for all things from a webbrowser etc, and having \
#              semi-intelligent scripts figure out what to do with those \
#              files. You write the scripts yourself. 

RETVAL=0
PROG=fsniper
EXEC=/usr/bin/fsniper
LOCK_FILE=/var/lock/subsys/fsniper
CONFIG_FILE=/etc/fsniper.conf


# Source function library.
. /etc/init.d/functions

[ -e /etc/sysconfig/$PROG ] && . /etc/sysconfig/$PROG

start() {
            [ -x $EXEC ] || exit 5
            echo -n $"Starting $PROG: "
            daemon --user=$USER $EXEC --daemon $CONFIG_FILE 1>/dev/null && success || failure
            RETVAL=$?
            [ "$RETVAL" = 0 ] && touch $LOCK_FILE
            echo
}

stop() {
        echo -n $"Stopping $PROG: "
        killproc $PROG
        RETVAL=$?
        [ "$RETVAL" = 0 ] && rm -f $LOCK_FILE
        echo
}

restart() {
        stop
        start
}

reload() {
        echo -n $"Reloading $PROG: "
        killproc $PROG -HUP
        echo
}

rh_status() {
    status $PROG
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        start
        ;;
    stop)
        rh_status_q || exit 0
        stop
        ;;
    restart|force-reload)
        stop
        start
        ;;
    reload)
        rh_status_q || exit 7
        reload
        ;;
    status)
        rh_status
        ;;

    condrestart|try-restart)
        if [ -f  $LOCK_FILE ]; then
            if [ "$RETVAL" = 0 ]; then
                stop
                sleep 3
                start
            fi
        fi
        ;;

    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        RETVAL=2
esac

exit $?