#!/bin/sh
#
# chkconfig: - 91 35
# description: Starts and stops the ALE naimas32 daemon \
#	       used to interface epliance with ePO 2.0.

export LD_LIBRARY_PATH=/opt/NETAepoagt/lib
export PROGROOT=/opt/NETAepoagt

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 1
fi

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
    initlog --facility=local1 --string="Network is not up! naimas32" --name="(ale)" --event=4 --priority=err
    initlog --facility=local7 --string="Network is not up! naimas32" --name="(ale)" --event=4
    echo_failure
    exit 2
fi

# Check that siteinfo.ini exists.
if [ ! -f ${PROGROOT}/siteinfo.ini ]
then
    initlog --facility=local1 --string="siteinfo.ini does not exist! naimas32" --name=(ale) --event=4 --priority=err
    initlog --facility=local7 --string="siteinfo.ini does not exist! naimas32" --name=(ale) --event=4
    echo_failure
    exit 3
fi

RETVAL=0

start() {
	echo -n "Starting ALE services: "
	daemon ${PROGROOT}/bin/naimas32
	RETVAL=$?
        if [ $RETVAL -eq 0 ]
        then
            echo_success
        else
            echo_failure
        fi
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ale || RETVAL=1
	echo ""
	return $RETVAL
}	
stop() {
	echo -n "Shutting down ALE services: "
	killproc naimas32
	RETVAL=$?
	echo ""
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ale
	echo ""
	return $RETVAL
}	
restart() {
	stop
	start
}	
rhstatus() {
	status naimas32
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	rhstatus
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 4
esac

exit $?

