Skip to content

Commit

Permalink
Merge pull request #9 from uchida/follow-linux-standard-base-exit-codes
Browse files Browse the repository at this point in the history
Follow Linux Standard Base exit codes for init script actions
  • Loading branch information
nramon committed Mar 5, 2015
2 parents 29a5800 + 03e4081 commit cc1e745
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
34 changes: 19 additions & 15 deletions pandora_server/util/pandora_server
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
;;

Expand All @@ -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" ]
Expand All @@ -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
Expand Down
28 changes: 16 additions & 12 deletions pandora_server/util/tentacle_serverd
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

;;
Expand All @@ -109,15 +113,15 @@ 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
_PID=`get_pid`

if [ "$_PID" = "$TENTACLE_PID" ]; then
echo "Tentacle Server could not be stopped"
rc_status -s
rc_failed
fi

echo "Stopping Tentacle Server"
Expand All @@ -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
Expand Down

0 comments on commit cc1e745

Please sign in to comment.