2009-09-21 22:26:23 +02:00
|
|
|
#!/bin/bash
|
2010-03-02 16:33:43 +01:00
|
|
|
# Copyright (c) 2005-2010 Artica ST
|
2009-09-21 02:34:14 +02:00
|
|
|
#
|
2010-08-29 23:41:22 +02:00
|
|
|
# Author: Sancho Lerena <slerena@artica.es> 2006-2010
|
2009-09-21 02:34:14 +02:00
|
|
|
#
|
|
|
|
# /etc/init.d/tentacle_server
|
|
|
|
#
|
|
|
|
# System startup script for Tentacle Server
|
|
|
|
#
|
2010-10-20 08:52:07 +02:00
|
|
|
# Comments to support chkconfig on RedHat Linux
|
|
|
|
# chkconfig: 2345 90 90
|
|
|
|
# description: Tentacle Server startup script
|
|
|
|
#
|
|
|
|
# Comments to support LSB init script conventions
|
2009-09-21 02:34:14 +02:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: tentacle_server
|
2009-08-12 17:01:55 +02:00
|
|
|
# Required-Start: $network
|
2009-09-21 02:34:14 +02:00
|
|
|
# Should-Start: $syslog
|
|
|
|
# Required-Stop: $network
|
|
|
|
# Should-Stop: $network
|
|
|
|
# Default-Start: 2 3 5
|
|
|
|
# Default-Stop: 0 1 6
|
2009-08-19 03:41:25 +02:00
|
|
|
# Short-Description: Tentacle Server startup script
|
2009-09-21 02:34:14 +02:00
|
|
|
# Description: Tentacle Server startup script
|
2009-08-12 17:01:55 +02:00
|
|
|
### END INIT INFO
|
2008-03-25 17:39:21 +01:00
|
|
|
|
2016-04-24 00:35:03 +02:00
|
|
|
if [ -x /lib/lsb/init-functions ]; then
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
fi
|
|
|
|
|
2016-04-01 09:59:06 +02:00
|
|
|
# Uses a wait limit before sending a KILL signal, before trying to stop
|
|
|
|
# Pandora FMS server nicely. Some big systems need some time before close
|
|
|
|
# all pending tasks / threads.
|
|
|
|
|
|
|
|
export MAXWAIT=60
|
|
|
|
|
2009-09-25 02:09:15 +02:00
|
|
|
# Check for SUSE status scripts
|
|
|
|
if [ -f /etc/rc.status ]
|
|
|
|
then
|
2010-03-02 16:33:43 +01:00
|
|
|
. /etc/rc.status
|
|
|
|
rc_reset
|
2009-09-25 02:09:15 +02:00
|
|
|
else
|
2014-09-10 16:56:27 +02:00
|
|
|
# Define part of rc functions for non-suse systems
|
|
|
|
function rc_status () {
|
|
|
|
RETVAL=$?
|
|
|
|
case $1 in
|
|
|
|
-v) RETVAL=0;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
function rc_exit () { exit $RETVAL; }
|
|
|
|
function rc_failed () { RETVAL=${1:-1}; }
|
|
|
|
RETVAL=0
|
2009-09-25 02:09:15 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
function get_pid {
|
2009-12-21 13:03:36 +01:00
|
|
|
# This sets COLUMNS to XXX chars, because if command is run
|
2010-03-02 16:33:43 +01:00
|
|
|
# in a "strech" term, ps aux don't report more than COLUMNS
|
|
|
|
# characters and this will not work.
|
|
|
|
COLUMNS=300
|
2018-04-30 15:53:09 +02:00
|
|
|
TENTACLE_PID=`ps -Af | grep "$TENTACLE_PATH$TENTACLE_DAEMON" | grep "$TENTACLE_CONFIG_FILE" | grep -v grep | tail -1 | awk '{ print $2 }'`
|
2010-03-02 16:33:43 +01:00
|
|
|
echo $TENTACLE_PID
|
2009-09-25 02:09:15 +02:00
|
|
|
}
|
|
|
|
|
2016-03-30 09:21:44 +02:00
|
|
|
function get_all_pid {
|
|
|
|
# This sets COLUMNS to XXX chars, because if command is run
|
|
|
|
# in a "strech" term, ps aux don't report more than COLUMNS
|
|
|
|
# characters and this will not work.
|
|
|
|
COLUMNS=300
|
|
|
|
TENTACLE_PIDS=`ps aux | grep "$TENTACLE_PATH$TENTACLE_DAEMON" | grep -v grep | awk '{ print $2 }'`
|
|
|
|
TENTACLE_PID="${TENTACLE_PIDS//\\n/' '}"
|
|
|
|
echo $TENTACLE_PID
|
|
|
|
}
|
|
|
|
|
2008-03-25 17:39:21 +01:00
|
|
|
# Tentacle server settings
|
|
|
|
TENTACLE_DAEMON="tentacle_server"
|
2009-12-18 19:22:33 +01:00
|
|
|
TENTACLE_PATH="/usr/bin"
|
2008-03-25 17:39:21 +01:00
|
|
|
TENTACLE_USER="pandora"
|
2018-04-30 15:53:09 +02:00
|
|
|
TENTACLE_CONFIG_FILE="/etc/tentacle/tentacle_server.conf"
|
|
|
|
TENTACLE_EXT_OPTS=""
|
2008-03-25 17:39:21 +01:00
|
|
|
|
2009-08-15 05:00:21 +02:00
|
|
|
# Set umask to 0002, because group MUST have access to write files to
|
|
|
|
# use remote file management on Pandora FMS Enterprise.
|
|
|
|
|
|
|
|
umask 0007
|
|
|
|
|
2008-03-25 17:39:21 +01:00
|
|
|
# Main script
|
2018-04-30 15:53:09 +02:00
|
|
|
TENTACLE_OPTS="-F $TENTACLE_CONFIG_FILE $TENTACLE_EXT_OPTS"
|
2008-03-25 17:39:21 +01:00
|
|
|
|
|
|
|
# Fix TENTACLE_PATH
|
|
|
|
case "$TENTACLE_PATH" in
|
|
|
|
*\/)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
TENTACLE_PATH="${TENTACLE_PATH}/"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ ! -f "${TENTACLE_PATH}$TENTACLE_DAEMON" ]; then
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Tentacle Server not found in ${TENTACLE_PATH}$TENTACLE_DAEMON"
|
2014-09-10 16:48:56 +02:00
|
|
|
rc_failed 5 # program is not installed
|
2009-09-25 02:09:15 +02:00
|
|
|
rc_exit
|
2008-03-25 17:39:21 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
2009-08-11 18:26:09 +02:00
|
|
|
start)
|
|
|
|
TENTACLE_PID=`get_pid`
|
2008-03-25 17:39:21 +01:00
|
|
|
if [ ! -z "$TENTACLE_PID" ]; then
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Tentacle Server is already running with PID $TENTACLE_PID"
|
2014-09-10 16:48:56 +02:00
|
|
|
rc_exit # running start on a service already running
|
2008-03-25 17:39:21 +01:00
|
|
|
fi
|
2018-04-30 15:53:09 +02:00
|
|
|
|
|
|
|
# Init the tentacle process
|
2009-09-04 14:18:42 +02:00
|
|
|
sudo -u $TENTACLE_USER ${TENTACLE_PATH}$TENTACLE_DAEMON $TENTACLE_OPTS
|
2009-09-25 02:09:15 +02:00
|
|
|
sleep 1
|
|
|
|
|
2009-08-11 18:26:09 +02:00
|
|
|
TENTACLE_PID=`get_pid`
|
2008-03-25 17:39:21 +01:00
|
|
|
if [ ! -z "$TENTACLE_PID" ]; then
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Tentacle Server is now running with PID $TENTACLE_PID"
|
2009-09-25 02:09:15 +02:00
|
|
|
rc_status -v
|
2008-03-25 17:39:21 +01:00
|
|
|
else
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Tentacle Server could not be started."
|
2014-09-10 16:48:56 +02:00
|
|
|
rc_failed 7 # program not running
|
2008-03-25 17:39:21 +01:00
|
|
|
fi
|
|
|
|
|
2009-08-11 18:26:09 +02:00
|
|
|
;;
|
2008-03-25 17:39:21 +01:00
|
|
|
|
|
|
|
stop)
|
2016-03-30 09:21:44 +02:00
|
|
|
TENTACLE_PID=`get_all_pid`
|
2008-03-25 17:39:21 +01:00
|
|
|
if [ -z "$TENTACLE_PID" ]; then
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Tentacle Server does not seem to be running"
|
2014-09-10 16:48:56 +02:00
|
|
|
rc_exit # running stop on a service already stopped or not running
|
2008-03-25 17:39:21 +01:00
|
|
|
else
|
2009-09-25 02:09:15 +02:00
|
|
|
kill $TENTACLE_PID
|
2016-04-01 09:59:06 +02:00
|
|
|
|
2016-04-07 11:26:18 +02:00
|
|
|
COUNTER=0
|
2016-04-01 09:59:06 +02:00
|
|
|
while [ $COUNTER -lt $MAXWAIT ]
|
|
|
|
do
|
|
|
|
_PID=`get_all_pid`
|
2016-04-07 11:34:24 +02:00
|
|
|
if [ "$_PID" != "$TENTACLE_PID" ]
|
2016-04-07 11:26:18 +02:00
|
|
|
# tentacle already stopped
|
2016-04-01 09:59:06 +02:00
|
|
|
then
|
|
|
|
COUNTER=$MAXWAIT
|
|
|
|
fi
|
|
|
|
COUNTER=`expr $COUNTER + 1`
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$_PID" = "$TENTACLE_PID" ]
|
|
|
|
then
|
|
|
|
kill -9 $TENTACLE_PID > /dev/null 2>&1
|
2008-03-25 17:39:21 +01:00
|
|
|
fi
|
2016-04-01 09:59:06 +02:00
|
|
|
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Stopping Tentacle Server"
|
2009-09-25 02:09:15 +02:00
|
|
|
rc_status -v
|
2008-03-25 17:39:21 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
force-reload|restart)
|
2009-08-11 18:26:09 +02:00
|
|
|
$0 stop
|
2009-09-25 02:09:15 +02:00
|
|
|
sleep 1
|
2009-08-11 18:26:09 +02:00
|
|
|
$0 start
|
2009-09-25 02:09:15 +02:00
|
|
|
rc_status
|
2009-08-11 18:26:09 +02:00
|
|
|
;;
|
2008-03-25 17:39:21 +01:00
|
|
|
|
|
|
|
status)
|
2009-08-11 18:26:09 +02:00
|
|
|
TENTACLE_PID=`get_pid`
|
2008-03-25 17:39:21 +01:00
|
|
|
if [ -z "$TENTACLE_PID" ]; then
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Tentacle Server is not running."
|
2014-09-10 16:48:56 +02:00
|
|
|
rc_failed 7 # program is not running
|
2008-03-25 17:39:21 +01:00
|
|
|
else
|
2010-08-29 23:41:22 +02:00
|
|
|
echo "Tentacle Server is running with PID $TENTACLE_PID."
|
2009-09-25 02:09:15 +02:00
|
|
|
rc_status
|
2008-03-25 17:39:21 +01:00
|
|
|
fi
|
|
|
|
|
2009-08-11 18:26:09 +02:00
|
|
|
;;
|
2008-03-25 17:39:21 +01:00
|
|
|
|
|
|
|
*)
|
2009-08-11 18:26:09 +02:00
|
|
|
echo "Usage: $0 {start | stop | restart | status}"
|
2008-03-25 17:39:21 +01:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-09-25 02:09:15 +02:00
|
|
|
rc_exit
|