#!/bin/sh
#
# codasrv
#
# chkconfig:	345 96 01
#
# description:	The Coda File Server
#

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

# Get network config
. /etc/sysconfig/network

# Check that networking is up
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down codasrv
		exit 1
	fi
else
	exit 0
fi

RETVAL=0
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/codasrv ]; then
		msg_starting codasrv
		startserver >/dev/null 2>&1 &
		RETVAL=$?
		ok
		[ RETVAL -eq 0 ] && touch /var/lock/subsys/codasrv
	else
		msg_already_running codasrv
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/codasrv ]; then
		msg_stopping codasrv
		busy
		volutil shutdown >/dev/null 2>&1
		ok
		show "Waiting for Coda server shutdown"
		busy
		while [ -f /var/lib/vice/srv/pid ]; do
			sleep 1
		done
		ok
		rm -f /var/lock/subsys/codasrv
	else
		msg_not_running codasrv
	fi
	;;
  status)
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
	;;
esac

exit $RETVAL
