#!/bin/bash
#
#      -*- OpenSAF  -*-
#
# (C) Copyright 2008 The OpenSAF Foundation
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
# under the GNU Lesser General Public License Version 2.1, February 1999.
# The complete license can be accessed from the following location:
# http://opensource.org/licenses/lgpl-license.php
# See the Copying file included with the OpenSAF distribution for full
# licensing terms.
#
# Author(s): Emerson Network Power, Erisson
#

echo "`date`: $0 $*"

CMD=$1

LOGDIR=/var/opt/amf_demo
RUNDIR=/var/run/amf_demo
AMFDEMO=/opt/amf_demo/amf_demo
PIDFILE="/var/run/${SA_AMF_COMPONENT_NAME}".pid

mkdir -p $RUNDIR
mkdir -p $LOGDIR

cleanup()
{
	if test -f $PIDFILE; then
		PID=`cat $PIDFILE`
		kill $PID 2> /dev/null
		rm $PIDFILE
	fi
}

instantiate()
{
	if [ ! -x $AMFDEMO ]; then
		logger -s -t $0 "ERROR: File $AMFDEMO does not exist or is not executable"
		exit 1
	fi

	cleanup

	$AMFDEMO $* >> ${LOGDIR}/amf_demo.log 2>&1 &

	echo $! > $PIDFILE
}

case "$CMD" in
	instantiate)
		instantiate $*
		;;
	cleanup)
		cleanup $*
		;;
	*)
		echo "Usage: $0 {instantiate|cleanup}"
		exit 1
esac

exit 0

