Pages: [1]   Go Down
Author Topic: Pandora Agent Start/Stop script for Debian + other updates  (Read 225 times)
0 Members and 1 Guest are viewing this topic.
daggett
Sr. Member
****

Karma: 0
Offline Offline

Posts: 109


View Profile
« on: January 11, 2007, 11:32:05 AM »

Hi all,
Here is a script that works on a Debian Linux distribution:
[code:1]#!/bin/bash
# Init.d script for Pandora FMS agent
# by Denis Chupau, Tranquil I.T. Systems
# this script was released under GNU/GPL license.
# This script is compatible with chkconfig

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
PANDORA_PATH=/opt/pandora/pandora_agent
DAEMON=pandora_agent
PIDFILE=/var/run/pandora_agent.pid

# chkconfig: 345 99 0
# description: Pandora_agent is a UNIX script that monitors the machines \
#              on which it runs. It collects informations about hardware and software \
#              then send them in a XML file via secured SSH connection to the server\
#              The Server parses, then stores , the XML data into a Mysql DB.
# processname: $DAEMON
# config: $PANDORA_PATH/pandora_agent.conf
# pidfile: $PIDFILE
#
### BEGIN INIT INFO
# Provides: pandora_agent
# Required-Start: $network
# Required-Stop: $network
# Default-Start: S 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The pandora_agent
# Description: Pandora_agent is a UNIX script that monitors the machines \
#              on which it runs. It collects informations about hardware and software \
#              then send them in a XML file via secured SSH connection to the server\
#              The Server parses, then stores , the XML data into a Mysql DB.
### END INIT INFO

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

RETVAL=0

if [ ! -f $PANDORA_PATH/$DAEMON"_daemon" ]
then
        echo "Pandora Agent not found at $PANDORA_PATH/$DAEMON"_daemon", please check setup"
        exit 1
fi

start() {
        if [ ! -f $PIDFILE ]
        then
                echo "Starting $DAEMON"
                $PANDORA_PATH/$DAEMON"_daemon"
                RETVAL=$?
                if [ $RETVAL -eq 0 ]
                then
                   echo '[  OK  ]'
                else
                   echo '[Failed]'
                fi
        else
                echo "Pandora Agent already running"
        fi
        return $RETVAL
}

stop()   {
   echo "Stopping $DAEMON daemon"
   PID2KILL=`ps -edf | grep -v grep | grep $DAEMON".sh" | awk '{print $2}' `
   echo "killing PID: "$PID2KILL
   kill $PID2KILL 2> /dev/null
   RETVAL=$?
   if [ $RETVAL -eq 0 ]
   then
      echo '[  OK  ]'
   else
      echo '[Failed]'
   fi
   rm -f $PIDFILE
   return $RETVAL
}

restart() {
        $0 stop
        $0 start
}

statusfn() {
        if [ -f $PIDFILE ]
        then
                REG_PID=$(cat $PIDFILE)
                if [ -n "$(ps -edf | grep $REG_PID | grep $DAEMON)" ]
                then
                        echo "$DAEMON ($REG_PID) is running..."
                else
                        echo "$DAEMON ($REG_PID) is dead but PID file exists"
                fi
        else
                echo "$DAEMON is not running"
        fi
}

case "$1" in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                restart
        ;;
        force-reload)
                restart
        ;;
        status)
                statusfn
                # if you have a compatible Linux Distribution, comment above line _AND_ uncomment next line
                # status $DAEMON
        ;;
        *)
                INITNAME=`basename $0`
                echo  "Usage: $INITNAME {start|stop|restart|force-reload|status}\n"
                exit 1
esac

exit $RETVAL
[/code]

It's not perfect, but it works on a very basic Debian system.

I also updated the start/stop scripts to correct some new bugs, and the agent installation script is completed with new functionalities.

bye for now
« Last Edit: January 01, 1970, 01:00:00 AM by daggett » Logged

Pages: [1]   Go Up
Print
 
Jump to:  


SourceForge.net Logo  This site is monitored by Pandora FMS   ArticaST