#!/bin/sh
#
#$Header:
##******************************************************************************
## Startup script for the LogTrend FtpAgent
##  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: FtpAgent
# pidfile: /var/run/FtpAgent.pid
# config: /usr/local/LogTrend/Agent/FtpAgent/Configuration.xml
##******************************************************************************
#$Log: logtrend-ftpagent.init,v $
#Revision 1.3  2002/07/26 12:15:37  jdive
#major fuck up cleanup
#
#Revision 1.2  2002/03/07 03:06:42  jdive
#fixed init script
#
#Revision 1.1  2002/02/26 04:12:06  jdive
#debian patch
#
#Revision 1.1  2001/12/13 15:33:37  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.1  2001/07/02 16:09:02  lsimonneau
#Add init.d files.
#

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/FtpAgent.pid

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

  stop)
        echo -n "Stopping LogTrend FtpAgent"
        if start-stop-daemon --quiet --stop --signal 0 --pidfile $PIDFILE --name FtpAgent
        then
                PID=`cat $PIDFILE`
                start-stop-daemon --stop --quiet --pidfile $PIDFILE --name FtpAgent
                # 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/FtpAgent.pid
        ;;
  status)
        status FtpAgent
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit 0

