#!/bin/sh
# Startup script for IBM WebSphere Application Server
# (C) COPYRIGHT International Business Machines Corp. 2003.
# author: Patrick Michel
# description: IBM's J2EE application server
#

# chkconfig: 35 86 14
# processname: java
# description: WebSphere Application Server (server1)
# pidfile:
# config: -
#
websphereBase=/opt/IBM/Quickr/AppServer
websphereBinPath=$websphereBase/bin
args=server1
prog="WebSphere Application Server"
proc=$websphereBase/java/jre/bin/java
wasUser=root
scriptName=wasserver
RETVAL=0

# verify installation
if [ ! -x $websphereBase ]; then
	echo "$prog is not installed"
	exit 0
fi

# source function library
. /etc/rc.d/init.d/functions

case "$1" in
start)
	echo -n "Starting $prog: "
	su - $wasUser -c "$websphereBinPath/startServer.sh $args > /dev/null"
	RETVAL=$?
	if [ $RETVAL = 0 ]; then
		touch /var/lock/subsys/$scriptName
		echo_success
	else
		echo_failure
	fi
	echo
;;
stop)
	echo -n "Stopping $prog: "
	su - $wasUser -c "$websphereBinPath/stopServer.sh $args > /dev/null"
	RETVAL=$?
	if [ $RETVAL = 0 ]; then
		rm -f /var/lock/subsys/$scriptName
		echo_success
	else
		echo_failure
	fi
	echo
;;
restart)
	$0 stop
	$0 start
;;
status)
	if [ ! -f $websphereBase/../wp_profile/logs/$args/$args.pid ]; then
		echo "$prog is stopped"
	else
		if [ -z $websphereBase/../wp_profile/logs/$args/$args.pid ]; then
			echo "$prog is stopped"
		else
			echo "$prog (pid `cat $websphereBase/../wp_profile/logs/$args/$args.pid`) is running..."
		fi 
	fi
;;
kill)
	echo "Killing $prog "
	if [ -f $websphereBase/../wp_profile/logs/$args/$args.pid ]; then
		kill -9 `cat $websphereBase/../wp_profile/logs/$args/$args.pid`
		rm -f /var/lock/subsys/$scriptName
		rm -f $websphereBase/../wp_profile/logs/$args/$args.pid
	else
		echo "$args is not running..."
	fi
;;
*)
echo "Usage: wasserver {start|stop|kill|restart|status}"
exit 1
esac

exit 0
