#! /bin/sh

USAGE_HELP="
Usage: urlcaptor command\n
\nCommands:\n
\tstart\tStarts the url image caption daemon\n
\tstop\tStops the url image caption daemon\n
\tstatus\tShows the status of the daemon
"

configFile="config.ini"

out=`grep "stdout" $configFile | sed -e "s/stdout=//"`
err=`grep "stderr" $configFile | sed -e "s/stderr=//"`

case "$1" in
	"start")
		./urlcaptord > $out 2> $err &
		echo "PID=$!" > urlcaptor.dat
		;;
	"stop")
		PID=`grep "PID" "urlcaptor.dat" | sed -e "s/PID=//"`
		kill $PID
		echo "PID=" > urlcaptor.dat
		;;
	"status")
		PID=`grep "PID" "urlcaptor.dat" | sed -e "s/PID=//"`
		if [ -z "$PID" ] ; then
			echo "stopped"
		else
			echo "running"
		fi
		;;
	*)
		echo $USAGE_HELP
		;;
esac
