#!/bin/bash
#
# ED-Agent    This shell script takes care of starting and stopping
#             standalone ED-agent.
#
# chkconfig: 345 81 79
# description: ED-agent is an enterprise discovery tool
# processname: discagnt
# config: none
#
### BEGIN INIT INFO
# Provides: discagnt
# Required-Start: $local_fs $network $syslog
# Should-Start:
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: ED-agent is an enterprise discovery tool
# Description: ED-agent is an enterprise discovery tool
### END INIT INFO
#
# Note:  Normally chkconfig tag with runlevel "345" can be replaced with "-"
# to not have a default runlevel.  Default-Start should also be changed to
# blank.

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

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

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /opt/ED-agent/bin/discagnt ] || exit 0

RETVAL=0
dir="/opt/ED-agent/bin"
prog="discagnt"

start() {
        # Start daemons.

        echo -n $"Starting $prog: "
        # Work around dynamic linker problem
        export HOME=/root
        $dir/$prog 2>&1 &
        disown -ar
        usleep 500000
        status $prog &> /dev/null && echo_success || echo_failure
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        echo
        return $RETVAL
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down $prog: "
        killproc $prog 
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        stop
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/$prog ]; then
            stop
            start
            RETVAL=$?
        fi
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $RETVAL
