#!/bin/sh

#$Header: /mnt/u1/cvs/logtrend/logtrend-linuxagent/debian/logtrend-linuxagent.init,v 1.2 2002/03/07 03:12:29 jdive Exp $
##******************************************************************************
## Startup script for the LogTrend LinuxAgent
##  Project      : LogTrend 1.0.0.0 - Atrid Systemes
##  Author       : Sylvain Lhullier s.lhullier@atrid.fr (05.03.2001)
# chkconfig: 345 85 15
# description: LogTrend is a supervision system
# processname: LinuxAgent
# pidfile: /var/run/LinuxAgent.pid
# config: /usr/local/LogTrend/Agent/LinuxAgent/Configuration.xml
##******************************************************************************
#$Log: logtrend-linuxagent.init,v $
#Revision 1.2  2002/03/07 03:12:29  jdive
#fixed init script
#
#Revision 1.1  2002/02/26 04:24:09  jdive
#debian patch
#
#Revision 1.1  2001/12/13 15:25:13  baux
#Added debian changes for version 0.81-1.
#
#Revision 1.1  2001/07/31 07:40:39  slhullier
#
#WidgetAgent/init.d/{deb|rh_mdk}.WidgetAgent -> WidgetAgent/init_d.{deb|rh_mdk}
#
#Revision 1.3  2001/07/24 14:38:41  slhullier
#
#Scripting for Visu
#
#Revision 1.2  2001/03/22 13:55:08  slhullier
#
#Option -r sans arg
#
#Revision 1.1  2001/03/05 15:32:57  slhullier
#
#Test ok sur frondon
#
#Revision 1.2  2001/02/21 09:33:40  slhullier
#
#Commentaires
#

PATH=/sbin/:$PATH

status() {
        # Test syntax.
        if [ $# = 0 ] ; then
                echo "Usage: status {program}"
                return 1
        fi

        # First try "pidof"
        pid=`pidof -o $$ -o $PPID -o %PPID -x $1`
        if [ "$pid" != "" ] ; then
                echo "$1 (pid $pid) is running..."
                return 0
        fi

        # Next try "/var/run/*.pid" files
        if [ -f /var/run/$1.pid ] ; then
                pid=`head -1 /var/run/$1.pid`
                if [ "$pid" != "" ] ; then
                        echo "$1 dead but pid file exists"
                        return 1
                fi
        fi
        # See if /var/lock/subsys/$1 exists
        if [ -f /var/lock/subsys/$1 ]; then
                echo "$1 dead but subsys locked"
                return 2
        fi
        echo "$1 is stopped"
        return 3
}


PIDFILE=/var/run/LinuxAgent.pid

# See how we were called.
case "$1" in
  start)
        echo -n "Starting LogTrend LinuxAgent"
        if start-stop-daemon --quiet --stop --signal 0 --pidfile $PIDFILE --name LinuxAgent 2>/dev/null
        then
                echo " already running."
                exit
        fi
        if /sbin/start-stop-daemon --start --quiet \
           --exec /usr/sbin/LinuxAgent -- -D -r -c /etc/logtrend/LinuxAgent/LinuxAgent.conf 2>/dev/null
        then
        	echo "."
        else
        	exit 1
        fi
        ;;

  stop)
        echo -n "Stopping LogTrend LinuxAgent"
        if start-stop-daemon --quiet --stop --signal 0 --pidfile $PIDFILE --name LinuxAgent 2>/dev/null
        then
                PID=`cat $PIDFILE`
                start-stop-daemon --stop --quiet --pidfile $PIDFILE --name LinuxAgent
                # Now we wait for it to die
                while kill -0 $PID 2>/dev/null; do sleep 1; done
                echo "."
        else
                echo " not running.";
        fi
        rm -f /var/run/LinuxAgent.pid
        ;;
  status)
        status LinuxAgent
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit 0

