#! /bin/bash
#
# easd          Start/Stop the CLIP cobra_serv daemon.
#
# chkconfig: 2345 90 60
# description: cobra-serv is CLIP Object Broker
# processname: easd
# config: /etc/eas/eas.ini
# pidfile: /var/run/crond.pid

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

RETVAL=0

# See how we were called.

prog="cobra_serv"

start() {
	echo -n $"Starting $prog: "
	cd /var/log/eas
	su -c "/usr/lib64/clip/cobra//cobra_serv /etc/eas/eas.ini" easserver >>server.log 2>>errors.log </dev/null &
	sleep 2
	pid=`pidof -s /usr/lib64/clip/cobra/cobra_serv`
	echo -ne "\r"
	if [ -z $pid ]; then
		echo_failure
		RETVAL=1
	else 
		echo_success
		RETVAL=0
		touch /var/lock/subsys/easd
	fi
	echo
}

stop() {
	echo -n $"Stopping $prog: "
	killall cobra_serv
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/easd
	return $RETVAL
}

rhstatus() {
	status cobra_serv
}

restart() {
  	stop
	start
}

reload() {
	echo -n $"Reloading cobra_serv daemon configuration: "
	killall cobra_serv -HUP
	retval=$?
	echo
	return $RETVAL
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/easd ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
	exit 1
esac

exit $?
