"Fossies" - the Fresh Open Source Software Archive

Member "pandora_server/util/pandora_server" (15 Sep 2021, 6852 Bytes) of package /linux/misc/pandorafms_server-7.0NG.757.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "pandora_server": 7.0NG.754_vs_7.0NG.755.

    1 #!/bin/bash
    2 # Copyright (c) 2005-2010 Artica ST
    3 #
    4 # Author: Sancho Lerena <slerena@artica.es> 2006-2010
    5 #
    6 # /etc/init.d/pandora_server
    7 #
    8 # System startup script for Pandora FMS
    9 #
   10 # Comments to support chkconfig on RedHat Linux
   11 # chkconfig: 2345 90 10
   12 # description: Pandora FMS Server startup scrip
   13 #
   14 # Comments to support LSB init script conventions
   15 ### BEGIN INIT INFO
   16 # Provides:       pandora_server
   17 # Required-Start: $syslog cron
   18 # Should-Start:   $network cron mysql
   19 # Required-Stop:  $syslog 
   20 # Should-Stop:    $network 
   21 # Default-Start:  2 3 5
   22 # Default-Stop:   0 1 6
   23 # Short-Description: Pandora FMS Server startup script
   24 # Description:    Pandora FMS Server startup script
   25 ### END INIT INFO
   26 
   27 if [ -x /lib/lsb/init-functions ]; then
   28 . /lib/lsb/init-functions
   29 fi
   30 
   31 # If you want to run several pandora servers in this machine, just copy 
   32 # this script to another name, editing PANDORA_HOME to the new .conf 
   33 
   34 export PANDORA_HOME="/etc/pandora/pandora_server.conf"
   35 export PANDORA_DAEMON=/usr/bin/pandora_server
   36 export PANDORA_HA=/usr/bin/pandora_ha
   37 export PID_DIR=/var/run
   38 
   39 # Environment variables
   40 if [ -f /etc/pandora/pandora_server.env ]; then
   41     source /etc/pandora/pandora_server.env
   42 fi
   43 if [[ -z ${PANDORA_RB_PRODUCT_NAME} ]]; then
   44     PANDORA_RB_PRODUCT_NAME="Pandora FMS"
   45 fi
   46 if [[ -z ${PANDORA_RB_COPYRIGHT_NOTICE} ]]; then
   47     PANDORA_RB_COPYRIGHT_NOTICE="Artica ST"
   48 fi
   49 
   50 export PANDORA_RB_PRODUCT_NAME=$PANDORA_RB_PRODUCT_NAME
   51 export PANDORA_RB_COPYRIGHT_NOTICE=$PANDORA_RB_COPYRIGHT_NOTICE
   52 
   53 # Uses a wait limit before sending a KILL signal, before trying to stop
   54 # Pandora FMS server nicely. Some big systems need some time before close
   55 # all pending tasks / threads.
   56 
   57 export MAXWAIT=60
   58 
   59 # Check for SUSE status scripts
   60 if [ -f /etc/rc.status ]
   61 then
   62     . /etc/rc.status
   63     rc_reset
   64 else
   65     # Define part of rc functions for non-suse systems
   66     function rc_status () {
   67         RETVAL=$?
   68         case $1 in
   69             -v) RETVAL=0;;
   70         esac
   71     }
   72     function rc_exit () { exit $RETVAL; }
   73     function rc_failed () { RETVAL=${1:-1}; }
   74     RETVAL=0
   75 fi
   76     
   77 # This function replace pidof, not working in the same way in different linux distros
   78 
   79 function pidof_pandora () {
   80     # This sets COLUMNS to XXX chars, because if command is run 
   81     # in a "strech" term, ps aux don't report more than COLUMNS
   82     # characters and this will not work. 
   83     COLUMNS=300
   84     PANDORA_PID=`ps aux | grep "$PANDORA_DAEMON $PANDORA_HOME" | grep -v grep | tail -1 | awk '{ print $2 }'`
   85     echo $PANDORA_PID
   86 }
   87 
   88 function pidof_pandora_ha () {
   89     # This sets COLUMNS to XXX chars, because if command is run 
   90     # in a "strech" term, ps aux don't report more than COLUMNS
   91     # characters and this will not work. 
   92     COLUMNS=300
   93     PANDORA_PID=`ps aux | grep "$PANDORA_HA -d -p $PID_DIR/pandora_ha.pid $PANDORA_HOME" | grep -v grep | tail -1 | awk '{ print $2 }'`
   94     echo $PANDORA_PID
   95 }
   96 
   97 
   98 # Main script
   99 
  100 if [ ! -f $PANDORA_DAEMON ]
  101 then
  102     echo "$PANDORA_RB_PRODUCT_NAME Server not found, please check setup and read manual"
  103     rc_failed 5 # program is not installed
  104     rc_exit
  105 fi
  106 
  107 case "$1" in
  108     start)
  109         PANDORA_PID=`pidof_pandora_ha`
  110         if [ ! -z "$PANDORA_PID" ]
  111         then
  112             echo "$PANDORA_RB_PRODUCT_NAME Server is currently running on this machine with PID ($PANDORA_PID)."
  113             rc_exit # running start on a service already running
  114         fi
  115 
  116         export PERL_LWP_SSL_VERIFY_HOSTNAME=0
  117         $PANDORA_HA -d -p $PID_DIR/pandora_ha.pid $PANDORA_HOME
  118         sleep 1
  119 
  120         PANDORA_PID=`pidof_pandora_ha`
  121         
  122         if [ ! -z "$PANDORA_PID" ]
  123         then
  124             echo "$PANDORA_RB_PRODUCT_NAME Server is now running with PID $PANDORA_PID"
  125             rc_status -v
  126         else
  127             echo "Cannot start $PANDORA_RB_PRODUCT_NAME HA. Aborted."
  128             echo "Check $PANDORA_RB_PRODUCT_NAME log files at '/var/log/pandora/pandora_server.error & pandora_server.log'"
  129             rc_failed 7 # program is not running
  130         fi
  131     ;;
  132         
  133     stop)
  134         PANDORA_PID=`pidof_pandora_ha`
  135         if [ -z "$PANDORA_PID" ]
  136         then
  137             echo "$PANDORA_RB_PRODUCT_NAME HA is not running, cannot stop it."
  138             rc_exit # running stop on a service already stopped or not running
  139         else
  140             echo "Stopping $PANDORA_RB_PRODUCT_NAME HA"
  141             kill $PANDORA_PID > /dev/null 2>&1
  142             COUNTER=0
  143 
  144             while [ $COUNTER -lt $MAXWAIT ]
  145             do
  146                 _PID=`pidof_pandora_ha`
  147                 if [ "$_PID" != "$PANDORA_PID" ]
  148                 then
  149                     COUNTER=$MAXWAIT
  150                 fi
  151                 COUNTER=`expr $COUNTER + 1`
  152                 sleep 1
  153             done
  154         
  155             # Send a KILL -9 signal to process, if it's alive after 60secs, we need
  156             # to be sure is really dead, and not pretending...
  157             if [ "$_PID" = "$PANDORA_PID" ]
  158             then
  159                 kill -9 $PANDORA_PID   > /dev/null 2>&1
  160             fi
  161             rc_status -v
  162         fi
  163     ;;
  164     status)
  165         PANDORA_PID=`pidof_pandora_ha`
  166         if [ -z "$PANDORA_PID" ]
  167         then
  168             echo "$PANDORA_RB_PRODUCT_NAME HA is not running."
  169             rc_failed 7 # program is not running
  170         else
  171             echo "$PANDORA_RB_PRODUCT_NAME HA is running with PID $PANDORA_PID."
  172             rc_status
  173         fi
  174     ;;
  175     start-server)
  176         PANDORA_PID=`pidof_pandora`
  177         if [ ! -z "$PANDORA_PID" ]
  178         then
  179             echo "$PANDORA_RB_PRODUCT_NAME Server is currently running on this machine with PID ($PANDORA_PID)."
  180             rc_exit # running start on a service already running
  181         fi
  182 
  183         export PERL_LWP_SSL_VERIFY_HOSTNAME=0
  184         $PANDORA_DAEMON $PANDORA_HOME -D
  185         sleep 1
  186 
  187         PANDORA_PID=`pidof_pandora`
  188         
  189         if [ ! -z "$PANDORA_PID" ]
  190         then
  191             echo "$PANDORA_RB_PRODUCT_NAME Server is now running with PID $PANDORA_PID"
  192             rc_status -v
  193         else
  194             echo "Cannot start $PANDORA_RB_PRODUCT_NAME Server. Aborted."
  195             echo "Check $PANDORA_RB_PRODUCT_NAME log files at '/var/log/pandora/pandora_server.error & pandora_server.log'"
  196             rc_failed 7 # program is not running
  197         fi
  198     ;;
  199         
  200     stop-server)
  201         PANDORA_PID=`pidof_pandora`
  202         if [ -z "$PANDORA_PID" ]
  203         then
  204             echo "$PANDORA_RB_PRODUCT_NAME Server is not running, cannot stop it."
  205             rc_exit # running stop on a service already stopped or not running
  206         else
  207             echo "Stopping $PANDORA_RB_PRODUCT_NAME Server"
  208             kill $PANDORA_PID > /dev/null 2>&1
  209             COUNTER=0
  210 
  211             while [ $COUNTER -lt $MAXWAIT ]
  212             do
  213                 _PID=`pidof_pandora`
  214                 if [ "$_PID" != "$PANDORA_PID" ]
  215                 then
  216                     COUNTER=$MAXWAIT
  217                 fi
  218                 COUNTER=`expr $COUNTER + 1`
  219                 sleep 1
  220             done
  221         
  222             # Send a KILL -9 signal to process, if it's alive after 60secs, we need
  223             # to be sure is really dead, and not pretending...
  224             if [ "$_PID" = "$PANDORA_PID" ]
  225             then
  226                 kill -9 $PANDORA_PID   > /dev/null 2>&1
  227             fi
  228             rc_status -v
  229         fi
  230     ;;
  231     status-server)
  232         PANDORA_PID=`pidof_pandora`
  233         if [ -z "$PANDORA_PID" ]
  234         then
  235             echo "$PANDORA_RB_PRODUCT_NAME Server is not running."
  236             rc_failed 7 # program is not running
  237         else
  238             echo "$PANDORA_RB_PRODUCT_NAME Server is running with PID $PANDORA_PID."
  239             rc_status
  240         fi
  241     ;;
  242     force-reload-server|restart-server)
  243         $0 stop-server
  244         $0 start-server
  245     ;;
  246     force-reload|restart)
  247         $0 stop
  248         $0 start
  249         ;;
  250     *)
  251         echo "Usage: pandora_server { start | stop | restart | status | start-server | stop-server | restart-server }"
  252         exit 1
  253 esac
  254 rc_exit