#!/bin/sh
#
# Script for controlling CDWserver
#
# chkconfig: 345 90 10
# description: CDWserver is part of webCDwriter. \
#              webCDwriter makes your local CD-writer available \
#              to the users in your network.
# processname: CDWserver
# pidfile: /var/run/CDWserver.pid
# config: /etc/CDWserver/config

# the path to your PID file
export pidFile=/var/run/CDWserver.pid

# the path to your CDWserver binary
CDWserver=/usr/local/sbin/CDWserver

# the path to your CDWserver config file
export CDWserverConfig=/etc/CDWserver/config

# See how we were called.
case "$1" in
	start)
		echo -n "Starting CDWserver: "
		if [ -f $pidFile ] \
			&& kill -0 `cat $pidFile` 2> /dev/null ; then
			echo "already running"
		else
			if $CDWserver ; then
				echo "done"
			else
				echo "could not be started"
			fi
		fi
		touch /var/lock/subsys/CDWserver
		;;
	stop)
		echo -n "Stopping CDWserver: "
		if [ -f $pidFile ] \
			&& kill -TERM `cat $pidFile` 2> /dev/null ; then
			rm -f $pidFile
			echo "done"
		else
			echo "no running CDWserver found"
		fi
		rm -f /var/lock/subsys/CDWserver
		;;
	restart)
		$0 stop
		$0 start
		;;
	status)
		lynx -dump http://localhost:10001
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
esac

exit 0

