pandorafms/pandora_server/util/tentacle_serverd

124 lines
2.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# Tentacle server simple startup script
# Copyright (c) 2007 Artica Soluciones Tecnologicas S.L.
# Linux Version (generic)
# v0.1 Build 090827
### BEGIN INIT INTO
# Provides: tentacle_server
# Default-Start: 2 3 5
# Default-Stop: 0 1 2 3 5
# Required-Start: $network
# Required-Stop: $network
# Short-Description: Tentacle Server startup script
### END INIT INFO
# Pandora server settings
PANDORA_SERVER_PATH="/var/spool/pandora/data_in"
# Tentacle server settings
TENTACLE_DAEMON="tentacle_server"
TENTACLE_PATH="/usr/local/bin"
TENTACLE_USER="pandora"
TENTACLE_ADDR="0.0.0.0"
TENTACLE_PORT="41121"
TENTACLE_EXT_OPTS="-i.*\.conf:conf;.*\.md5:md5"
# Set umask to 0002, because group MUST have access to write files to
# use remote file management on Pandora FMS Enterprise.
umask 0007
# Sets the shell variable TENTACLE_PID to the PID of the Tentacle server (empty
# if not running). Can be a list of PIDs if multiple instances are running.
function get_pid {
TENTACLE_PID=`ps aux | grep $TENTACLE_PATH$TENTACLE_DAEMON | grep -v grep | tail -1 | awk '{ print $2 }'`
echo $TENTACLE_PID
}
# Main script
TENTACLE_OPTS="-a $TENTACLE_ADDR -p $TENTACLE_PORT -s $PANDORA_SERVER_PATH $TENTACLE_EXT_OPTS -d"
# Fix TENTACLE_PATH
case "$TENTACLE_PATH" in
*\/)
;;
*)
TENTACLE_PATH="${TENTACLE_PATH}/"
;;
esac
if [ ! -f "${TENTACLE_PATH}$TENTACLE_DAEMON" ]; then
echo "Tentacle server not found in ${TENTACLE_PATH}$TENTACLE_DAEMON."
exit 1
fi
case "$1" in
start)
TENTACLE_PID=`get_pid`
if [ ! -z "$TENTACLE_PID" ]; then
echo "Tentacle server is already running with PID $TENTACLE_PID."
exit 1
fi
sudo -u $TENTACLE_USER ${TENTACLE_PATH}$TENTACLE_DAEMON $TENTACLE_OPTS
sleep 1
TENTACLE_PID=`get_pid`
if [ ! -z "$TENTACLE_PID" ]; then
echo "Tentacle server is now running with PID $TENTACLE_PID."
else
echo "Tentacle server could not be started."
exit 1
fi
exit 0
;;
stop)
TENTACLE_PID=`get_pid`
if [ -z "$TENTACLE_PID" ]; then
echo "Tentacle server does not seem to be running."
exit 1;
else
kill $TENTACLE_PID > /dev/null 2>&1
sleep 1
get_pid
if [ ! -z "$TENTACLE_PID" ]; then
echo "Tentacle server could not be stopped."
exit 1
fi
echo "Tentacle server stopped."
fi
exit 0
;;
force-reload|restart)
$0 stop
$0 start
;;
status)
TENTACLE_PID=`get_pid`
if [ -z "$TENTACLE_PID" ]; then
echo "Tentacle server is not running."
else
echo "Tentacle server is running with PID $TENTACLE_PID."
fi
exit 0
;;
*)
echo "Usage: $0 {start | stop | restart | status}"
exit 1
;;
esac