#! /bin/bash
#
# Original Author: Dimitrios Dimitrakos mail@dimitrios.de
# Modified for c't-Distro/Debian: Peter Siering <ps@ctmagazin.de>
#
# Activate only for Debug
LOGFILE=/var/log/vdrconvert.log
#LOGFILE=/dev/null
#set -x

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="vdrconvert"
DAEMON="/usr/lib/vdrconvert/bin/vdrconvert.sh"
CONFFILE="/etc/vdr/vdrconvert/vdrconvert.conf"
test -x $DAEMON || exit 0
test -f $CONFFILE || exit 0

. $CONFFILE

function start_vdrconvert ()
{
	start-stop-daemon --start --quiet \
	    --exec $DAEMON \
	    --make-pidfile --background \
	    --pidfile /var/run/vdrconvert.pid \
	    --  " > $LOGFILE 2>&1"
}

function stop_vdrconvert ()
{
	start-stop-daemon --stop \
	    --pidfile /var/run/vdrconvert.pid \
	    --retry 5 --oknodo > /dev/null
}   

case "$1" in
    start)
        echo -n "Starting $DESC"
	start_vdrconvert
        echo "."
	;;
    stop)
	echo -n "Stopping $DESC"
	stop_vdrconvert
        echo "."
	;;
    restart)
    	echo -n "Restarting $DESC"
	stop_vdrconvert && start_vdrconvert
	echo "."
    ;;
    force-reload)
    	$0 restart
    ;;
    *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac
# rc_exit
