#!/bin/sh
#
# ibmasm        This shell script takes care of starting and stopping \
#               the IBM Remote Supervisor Adapter II daemon.
#
# chkconfig: 2345 85 15
# description: The IBM Remote Supervisor Adapter II interface daemon allows\
#              software to interact with the Remote Supervisor Adapter II.\
#
# processname:	ibmasm
# pidfile: /var/run/ibmusbasm.pid
#
# $Id: ibmusbasm.init,v 1.6 2009/06/17 03:01:46 glen Exp $

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

# Get service config - may override defaults
[ -f /etc/sysconfig/ibmasm ] && . /etc/sysconfig/ibmasm

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/ibmasm ]; then
		msg_already_running "IBM Remote Supervisor Adapter"
		return
	fi

	msg_starting "IBM Remote Supervisor Adapter"
	# start the daemon in the background
	# it will take some time to initialize and it will check using
	# /var/lock/subsys/ibmusbasm lockfile to see if it's not already running,
	# so don't use that as lockfile for initscript.
	daemon --fork /sbin/ibmasm
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ibmasm
}

stop() {
	if [ ! -f /var/lock/subsys/ibmasm ]; then
		msg_not_running "IBM Remote Supervisor Adapter"
		return
	fi

	# Stop daemons.
	msg_stopping "IBM Remote Supervisor Adapter"
	killproc --pidfile /var/run/ibmusbasm.pid ibmasm -TERM
	rm -f /var/lock/subsys/ibmasm
}

condrestart() {
	if [ ! -f /var/lock/subsys/ibmasm ]; then
		msg_not_running "IBM Remote Supervisor Adapter"
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status ibmasm
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
