#!/bin/bash

#------------------------------------------------------------
#
#  Copyright Mission Critical Linux, 2000

#  Kimberlite is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version.

#  Kimberlite 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.  See the GNU
#  General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with Kimberlite; see the file COPYING.  If not, write to the
#  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
#  MA 02139, USA.
#
#
#  Author: Gregory P. Myrdal <Myrdal@MissionCriticalLinux.Com>
#
#------------------------------------------------------------

#
# This file contains a template that you can use to create a script 
# that will start and stop an application used in a cluster service.
#

#------------------------------------------------------------
# Variable definitions
#------------------------------------------------------------

cluDir=/opt/cluster/bin
PATH=$PATH:$cluDir
export PATH
MYNAME=$(basename $0)

# The clug utility uses the normal logging levels as defined in
# sys/syslog.h.  Calls to clulog will use the logging level defined
# for the Service Manager (svcmgr).

LOG_EMERG=0	# system is unusable
LOG_ALERT=1	# action must be taken immediately
LOG_CRIT=2	# critical conditions
LOG_ERR=3	# error conditions
LOG_WARNING=4	# warning conditions
LOG_NOTICE=5	# normal but significant condition
LOG_INFO=6	# informational
LOG_DEBUG=7	# debug-level messages

#------------------------------------------------------------
# Start of execution
#------------------------------------------------------------

if [ $# -ne 2 ]; then
	echo "Usage: $0 {start, stop} service_name"
	exit 1
fi

action=$1		# type of action, i.e. 'start' or 'stop'
svcName=$2		# name of the service

#
# Record all output into a temp file in case of error
#
exec > /tmp/$MYNAME.$action.log 2>&1

clulog -s $LOG_DEBUG "In $0 with action=$action, svcName=$svcName"

case $action in
'start')
	clulog -s $LOG_INFO "Running user start script for service $svcName"
	#
	# <<< EDIT HERE: Add service start specfic code here >>>
	#
	;;
'stop')
	clulog -s $LOG_INFO "Running user stop script for service $svcName"
	#
	# <<< EDIT HERE: Add service stop specfic code here >>>
	#
	;;
*)
	clulog -s $LOG_ERR \
		"Unknown action '$action' passed to $svcName user script"
	exit 1		# return failure
esac

exit 0			# return success
