Merge pull request #9 from uchida/follow-linux-standard-base-exit-codes
Follow Linux Standard Base exit codes for init script actions
This commit is contained in:
commit
cc1e745295
|
@ -42,30 +42,35 @@ then
|
|||
. /etc/rc.status
|
||||
rc_reset
|
||||
else
|
||||
# Define rc functions for non-suse systems, "void" functions.
|
||||
function rc_status () { VOID=1; }
|
||||
function rc_exit () { exit; }
|
||||
function rc_failed () { VOID=1; }
|
||||
|
||||
# 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
|
||||
fi
|
||||
|
||||
# This function replace pidof, not working in the same way in different linux distros
|
||||
|
||||
function pidof_pandora () (
|
||||
function pidof_pandora () {
|
||||
# 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
|
||||
PANDORA_PID=`ps aux | grep "$PANDORA_DAEMON $PANDORA_HOME" | grep -v grep | tail -1 | awk '{ print $2 }'`
|
||||
echo $PANDORA_PID
|
||||
)
|
||||
}
|
||||
|
||||
# Main script
|
||||
|
||||
if [ ! -f $PANDORA_DAEMON ]
|
||||
then
|
||||
echo "Pandora FMS Server not found, please check setup and read manual"
|
||||
rc_status -s
|
||||
rc_failed 5 # program is not installed
|
||||
rc_exit
|
||||
fi
|
||||
|
||||
|
@ -74,9 +79,8 @@ case "$1" in
|
|||
PANDORA_PID=`pidof_pandora`
|
||||
if [ ! -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "Pandora FMS Server is currently running on this machine with PID ($PANDORA_PID). Aborting now..."
|
||||
rc_failed 1
|
||||
rc_exit
|
||||
echo "Pandora FMS Server is currently running on this machine with PID ($PANDORA_PID)."
|
||||
rc_exit # running start on a service already running
|
||||
fi
|
||||
|
||||
$PANDORA_DAEMON $PANDORA_HOME -D
|
||||
|
@ -91,7 +95,7 @@ case "$1" in
|
|||
else
|
||||
echo "Cannot start Pandora FMS Server. Aborted."
|
||||
echo "Check Pandora FMS log files at '/var/log/pandora/pandora_server.error & pandora_server.log'"
|
||||
rc_status -s
|
||||
rc_failed 7 # program is not running
|
||||
fi
|
||||
;;
|
||||
|
||||
|
@ -100,13 +104,13 @@ case "$1" in
|
|||
if [ -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "Pandora FMS Server is not running, cannot stop it."
|
||||
rc_failed
|
||||
rc_exit # running stop on a service already stopped or not running
|
||||
else
|
||||
echo "Stopping Pandora FMS Server"
|
||||
kill $PANDORA_PID > /dev/null 2>&1
|
||||
COUNTER=0
|
||||
|
||||
while [ $COUNTER -lt $MAXWAIT ]
|
||||
while [ $COUNTER -lt $MAXWAIT ]
|
||||
do
|
||||
_PID=`pidof_pandora`
|
||||
if [ "$_PID" != "$PANDORA_PID" ]
|
||||
|
@ -131,7 +135,7 @@ case "$1" in
|
|||
if [ -z "$PANDORA_PID" ]
|
||||
then
|
||||
echo "Pandora FMS Server is not running."
|
||||
rc_status
|
||||
rc_failed 7 # program is not running
|
||||
else
|
||||
echo "Pandora FMS Server is running with PID $PANDORA_PID."
|
||||
rc_status
|
||||
|
|
|
@ -30,11 +30,16 @@ then
|
|||
. /etc/rc.status
|
||||
rc_reset
|
||||
else
|
||||
# Define rc functions for non-suse systems, "void" functions.
|
||||
function rc_status () { VOID=1; }
|
||||
function rc_exit () { exit; }
|
||||
function rc_failed () { VOID=1; }
|
||||
|
||||
# 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
|
||||
fi
|
||||
|
||||
function get_pid {
|
||||
|
@ -77,7 +82,7 @@ esac
|
|||
|
||||
if [ ! -f "${TENTACLE_PATH}$TENTACLE_DAEMON" ]; then
|
||||
echo "Tentacle Server not found in ${TENTACLE_PATH}$TENTACLE_DAEMON"
|
||||
rc_failed 1
|
||||
rc_failed 5 # program is not installed
|
||||
rc_exit
|
||||
fi
|
||||
|
||||
|
@ -86,8 +91,7 @@ case "$1" in
|
|||
TENTACLE_PID=`get_pid`
|
||||
if [ ! -z "$TENTACLE_PID" ]; then
|
||||
echo "Tentacle Server is already running with PID $TENTACLE_PID"
|
||||
rc_failed 2
|
||||
rc_exit
|
||||
rc_exit # running start on a service already running
|
||||
fi
|
||||
|
||||
sudo -u $TENTACLE_USER ${TENTACLE_PATH}$TENTACLE_DAEMON $TENTACLE_OPTS
|
||||
|
@ -100,7 +104,7 @@ case "$1" in
|
|||
else
|
||||
echo "Tentacle Server could not be started."
|
||||
echo "Verify that port $TENTACLE_PORT is not used."
|
||||
rc_status -v
|
||||
rc_failed 7 # program not running
|
||||
fi
|
||||
|
||||
;;
|
||||
|
@ -109,7 +113,7 @@ case "$1" in
|
|||
TENTACLE_PID=`get_pid`
|
||||
if [ -z "$TENTACLE_PID" ]; then
|
||||
echo "Tentacle Server does not seem to be running"
|
||||
rc_failed 2
|
||||
rc_exit # running stop on a service already stopped or not running
|
||||
else
|
||||
kill $TENTACLE_PID
|
||||
sleep 1
|
||||
|
@ -117,7 +121,7 @@ case "$1" in
|
|||
|
||||
if [ "$_PID" = "$TENTACLE_PID" ]; then
|
||||
echo "Tentacle Server could not be stopped"
|
||||
rc_status -s
|
||||
rc_failed
|
||||
fi
|
||||
|
||||
echo "Stopping Tentacle Server"
|
||||
|
@ -137,7 +141,7 @@ case "$1" in
|
|||
TENTACLE_PID=`get_pid`
|
||||
if [ -z "$TENTACLE_PID" ]; then
|
||||
echo "Tentacle Server is not running."
|
||||
rc_status
|
||||
rc_failed 7 # program is not running
|
||||
else
|
||||
echo "Tentacle Server is running with PID $TENTACLE_PID."
|
||||
rc_status
|
||||
|
|
Loading…
Reference in New Issue