#!/bin/ksh
#
# Component: collab
#
# Description:
#  Control script of component collab
#
# Last Updated     : $Author$
# Update Date Time : $Date$
# RCS File Name    : $RCSfile$
# RCS Revision     : $Revision$
# Locked by        : $Locker$
# Symbolic name    : $Name$
# State            : $State$
#

#--- INIT ------------------------------
#needs $HOME
. $HOME/etc/ctrl.main.shi

[ -f $HOME/etc/setenv.sh ] && . $HOME/etc/setenv.sh

#--- FUNC ------------------------------
do_shell_()
{
	if [ -f "$ETC/virthost.sh" ]; then
		. "$ETC/virthost.sh"
	fi
	[ -z "$COLLAB_PID" ] && COLLAB_PORT=1459

	cat <<-EndOfInlineData
		COLLAB_HOME=$HOME/component/collab
		COLLAB_VAR=$VAR/collab
		COLLAB_PORT=$COLLAB_PORT
		COLLAB_PID=\$RUN/collab.pid
	EndOfInlineData

} #do_shell_()

do_stop_()
{
	if [ -f $COLLAB_PID ] ; then
		echo stopping collab daemon
		kill `cat "$COLLAB_PID" 2>&1`
		rm $COLLAB_PID
	fi
}

do_start_()
{
	# Create var/collab if doesn't exist yet
	[ ! -d "$COLLAB_VAR" ] && mkdir "$COLLAB_VAR" 

	echo starting collab daemon
	$COLLAB_HOME/collab -p $COLLAB_PORT >/dev/null 2>&1 &
	echo $! > $COLLAB_PID

} #do_start_()

do_beforesubmit_()
{
	do_stop_

} #do_beforesubmit_()

do_aftersubmit_()
{
	do_start_

} #do_aftersubmit_()


#--- MAIN ------------------------------
check_action_ $1
if [ 0 = $? ]; then
	do_$1_

else
	echo "--- Component collab [ctrl $$]: Bad command: $1" >&2
	exit 1

fi
