#!/bin/bash
# Watches upload directory and extracts incoming archives into ABRT dump
# location
#
# chkconfig: 35 82 16
# description: ABRT upload watch
### BEGIN INIT INFO
# Provides: abrt-upload-watch
# Required-Start: $abrtd
# Default-Stop: 0 1 2 6
# Default-Start: 3 5
# Short-Description: ABRT upload watch
# Description: Extracts incoming ABRT archives into ABRT dump location
### END INIT INFO

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

PROG="abrt-upload-watch"
LOCKFILE="/var/lock/subsys/$PROG"
EXEC="/usr/sbin/$PROG"

start() {
    [ -x $EXEC ] || exit 5
    echo -n $"Starting '$PROG': "
    daemon $EXEC -d
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $LOCKFILE
    return $RETVAL
}

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

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    status $PROG
}

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

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac
exit $?
