#!/bin/sh
#
# update
#
# chkconfig:	345 95 02
#
# description:	The Coda update server and clients
#

# 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 update
		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/update ]; then
		msg_starting rpc2portmap
		daemon rpc2portmap
		RETVAL=$?
		msg_starting updatesrv
		daemon updatesrv
		RET=$?
		[ RETVAL -eq 0 ] && RETVAL=$RET
		msg_starting updateclnt
		daemon updateclnt -h `cat /var/lib/vice/db/scm`
		RET=$?
		if [ RETVAL -eq 0 ] && RETVAL=$RET
		[ RETVAL -eq 0 ] && touch /var/lock/subsys/update
	else
		msg_already_running update
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/update ]; then
		msg_stopping updateclnt
		killproc updateclnt
		msg_stopping updatesrv
		killproc updatesrv
		msg_stopping rpc2portmap
		killproc rpc2portmap
		rm -f /var/lock/subsys/update
	else
		msg_not_running update
	fi
	;;
  status)
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
	;;
esac

exit $RETVAL
