pandorafms/pandora_agents/linux/pandora_agent_daemon

64 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# Init script for Pandora FMS agent
# Script de arranque del agente Pandora FMS
# Generic GNU/Linux version
# Version para GNU/Linux (generico)
# Sancho Lerena, <slerena@artica.es>
# v1.2
### 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: start/stop pandora-agent daemon
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
PANDORA_PATH=/opt/pandora_agent/
DAEMON=pandora_agent.sh
PIDFILE=/var/run/pandora_agent.pid
if [ ! -f $PANDORA_PATH/$DAEMON ]
then
echo "Pandora Agent not found at $PANDORA_PATH/$DAEMON, please check setup"
exit
fi
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "Pandora Agent is currently running on this machine. Aborting now..."
exit
fi
$PANDORA_PATH/$DAEMON $PANDORA_PATH >> $PANDORA_PATH/pandora.log & MYPID=$!
echo $MYPID > $PIDFILE
echo "Pandora Agent is now running with PID $MYPID"
;;
stop)
if [ -f $PIDFILE ]
then
echo "Stopping Pandora Agent."
PID_2=`cat $PIDFILE`
if [ ! -z "`ps -f -p $PID_2 | grep -v grep | grep 'pandora_agent'`" ]
then
kill -9 $PID_2
fi
rm -f $PIDFILE
else
echo "Pandora Agent is not running, cannot stop it. Aborting now..."
fi
;;
force-reload|restart)
$0 stop
$0 start
;;
*)
echo "Uso: /etc/init.d/pandora_agent {start|stop|restart|force-reload}"
exit 1
esac