#!/bin/ksh
#
# Component: dotcom
#
# Description:
#  Control script of component dotcom
#
# Last Updated     : $Author: tnemeth $
# Update Date Time : $Date: 2010/04/16 08:03:56 $
# RCS File Name    : $RCSfile: ctrl,v $
# RCS Revision     : $Revision: 1.5.8.1 $
# Locked by        : $Locker:  $
# Symbolic name    : $Name: PATCH-6-2 $
# State            : $State: Exp $

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

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

#--- FUNC ------------------------------
do_shell_()
{
	cat <<-EndOfInlineData
		DOTCOM_HOME=$HOME/component/dotcom
	EndOfInlineData

} #do_shell_()


do_crontab_()
{
	# Get time from crontabSchedule settings for starting recollect dotcom info
	[ -f "$CONF/crontabSchedule.shi" ] && . $CONF/crontabSchedule.shi
	[ -z "$ReCollectDotcom" ] && ReCollectDotcom="18 01"

	cat <<-EOI
		$ReCollectDotcom * * * $TASKD_HOME/runjavacmd -c "0 dotcom.ReCollect" -p $JAVA_SERVER_PORT
	EOI
}


do_start_()
{
	# Start recollect if no dotcom.jcfg exists
	if [ ! -f "$CONF/dotcom.jcfg" ] ; then
		echo "start re-collecting dotcom configuration"
		counter=0
		while [ $counter -lt 5 ] ; do
			$TASKD_HOME/runjavacmd -c "0 dotcom.ReCollect" -p $JAVA_SERVER_PORT
			[ $? -eq 0 ] && break
			counter=$(( $counter + 1 ))
			sleep 1
		done
		if [ ! -f "$CONF/dotcom.jcfg" ] ; then
			echo "Collecting dotcom configuration failed"
		fi
	fi
}

#
# List files/tables to be backed up grouped by categories
#
# output lines should be in '<category> <type> <names>' format
#
do_listbackup_()
{
	# This file can be re-generated - do it in afterrestore
	cat <<-EOFLISTBACKUP
		nobackup.nobackup FILE ${CONF#$HOME/}/dotcom.jcfg
	EOFLISTBACKUP
}

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

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

fi
