Welcome to Pandora FMS Community!

Find answers, ask questions, and connect with our community around the world.

Welcome to Pandora FMS Community Forums Community support Pandora Agent Start/Stop script for Debian + other updates

  • Pandora Agent Start/Stop script for Debian + other updates

    Posted by daggett on January 11, 2007 at 14:32

    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

    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

    daggett replied 18 years, 1 month ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.