#!/bin/sh
# start/stop webfsd.

test -f /usr/bin/webfsd 	|| exit 0
test -f /etc/webfsd.conf	|| exit 0

# read + verify config
. /etc/webfsd.conf
test "$web_root" = ""		&& exit 0

# pidfile handling
pidfile=/var/run/webfs/webfsd.pid
pidfdir=`dirname $pidfile`
mkdir -p $pidfdir
test "$web_user"  != ""	&& chown $web_user  $pidfdir
test "$web_group" != ""	&& chgrp $web_group $pidfdir

# build command line
ARGS="-k $pidfile -r $web_root"
test "$web_host"	!= ""	&& ARGS="$ARGS -n $web_host"
test "$web_ip"		!= ""	&& ARGS="$ARGS -i $web_ip"
test "$web_port"	!= ""	&& ARGS="$ARGS -p $web_port"
test "$web_timeout"	!= ""	&& ARGS="$ARGS -t $web_timeout"
test "$web_conn"	!= ""	&& ARGS="$ARGS -c $web_conn"
test "$web_dircache"	!= ""	&& ARGS="$ARGS -a $web_dircache"
test "$web_index"	!= ""	&& ARGS="$ARGS -f $web_index"
test "$web_accesslog"	!= ""	&& ARGS="$ARGS -l $web_accesslog"
test "$web_syslog" = "true"	&& ARGS="$ARGS -s"
test "$web_virtual" = "true"	&& ARGS="$ARGS -v"
test "$web_user"	!= ""	&& ARGS="$ARGS -u $web_user"
test "$web_group"	!= ""	&& ARGS="$ARGS -g $web_group"
#echo "debug: webfsd $ARGS"

case "$1" in
start)
	echo -n "Starting httpd daemon: webfsd"
	start-stop-daemon --start --quiet --pidfile $pidfile \
		--startas /usr/bin/webfsd -- $ARGS
	echo "." 
	;;
stop)
	echo -n "Stopping httpd daemon: webfsd"
	start-stop-daemon --stop --quiet --pidfile $pidfile
	echo "."
	;;
restart|force-reload)
	echo -n "Re-starting httpd daemon: webfsd"
	start-stop-daemon --stop --quiet --pidfile $pidfile
	start-stop-daemon --start --quiet --pidfile $pidfile \
		--startas /usr/bin/webfsd -- $ARGS
	echo "."
	;;
*)
	echo "Usage: /etc/init.d/webfsd start|stop|restart|force-reload"
	exit 1 
	;;
esac
exit 0

