Issue #344 (init script does not properly display status of a non running service).

This commit is contained in:
Simone Bordet 2016-02-19 12:36:50 +01:00
parent 1d04b9ece0
commit df32714e8d

View File

@ -18,19 +18,19 @@ NAME=$(echo $(basename $0) | sed -e 's/^[SK][0-9]*//' -e 's/\.sh$//')
# Configuration files
#
# /etc/default/$NAME
# If it exists, this is read at the start of script. It may perform any
# If it exists, this is read at the start of script. It may perform any
# sequence of shell commands, like setting relevant environment variables.
#
# $HOME/.$NAMErc (e.g. $HOME/.jettyrc)
# If it exists, this is read at the start of script. It may perform any
# If it exists, this is read at the start of script. It may perform any
# sequence of shell commands, like setting relevant environment variables.
#
# /etc/$NAME.conf
# If found, and no configurations were given on the command line,
# the file will be used as this script's configuration.
# the file will be used as this script's configuration.
# Each line in the file may contain:
# - A comment denoted by the pound (#) sign as first non-blank character.
# - The path to a regular file, which will be passed to jetty as a
# - The path to a regular file, which will be passed to jetty as a
# config.xml file.
# - The path to a directory. Each *.xml file in the directory will be
# passed to jetty as a config.xml file.
@ -62,10 +62,10 @@ NAME=$(echo $(basename $0) | sed -e 's/^[SK][0-9]*//' -e 's/\.sh$//')
# Where the $NAME.pid file should be stored. It defaults to the
# first available of /var/run, /usr/var/run, JETTY_BASE and /tmp
# if not set.
#
#
# JETTY_PID
# The Jetty PID file, defaults to $JETTY_RUN/$NAME.pid
#
#
# JETTY_ARGS
# The default arguments to pass to jetty.
# For example
@ -97,10 +97,10 @@ findDirectory()
local L OP=$1
shift
for L in "$@"; do
[ "$OP" "$L" ] || continue
[ "$OP" "$L" ] || continue
printf %s "$L"
break
done
done
}
running()
@ -118,7 +118,7 @@ running()
started()
{
# wait for 60s to see "STARTED" in PID file, needs jetty-started.xml as argument
for T in 1 2 3 4 5 6 7 9 10 11 12 13 14 15
for T in 1 2 3 4 5 6 7 9 10 11 12 13 14 15
do
sleep 4
[ -z "$(grep STARTED $1 2>/dev/null)" ] || return 0
@ -162,12 +162,12 @@ shift
##################################################
ETC=/etc
if [ $UID != 0 ]
then
then
ETC=$HOME/etc
fi
for CONFIG in {/etc,~/etc}/default/${NAME}{,9} $HOME/.${NAME}rc; do
if [ -f "$CONFIG" ] ; then
if [ -f "$CONFIG" ] ; then
readConfig "$CONFIG"
fi
done
@ -187,7 +187,7 @@ JETTY_INSTALL_TRACE_FILE="start.jar"
##################################################
# Try to determine JETTY_HOME if not set
##################################################
if [ -z "$JETTY_HOME" ]
if [ -z "$JETTY_HOME" ]
then
JETTY_SH=$0
case "$JETTY_SH" in
@ -200,7 +200,7 @@ then
esac
if [ ! -f "$JETTY_HOME/$JETTY_INSTALL_TRACE_FILE" ]
then
then
JETTY_HOME=
fi
fi
@ -210,7 +210,7 @@ fi
# No JETTY_HOME yet? We're out of luck!
##################################################
if [ -z "$JETTY_HOME" ]; then
echo "** ERROR: JETTY_HOME not set, you need to set it or install in a standard location"
echo "** ERROR: JETTY_HOME not set, you need to set it or install in a standard location"
exit 1
fi
@ -219,7 +219,7 @@ JETTY_HOME=$PWD
##################################################
# Set JETTY_BASE
# Set JETTY_BASE
##################################################
if [ -z "$JETTY_BASE" ]; then
JETTY_BASE=$JETTY_HOME
@ -232,7 +232,7 @@ JETTY_BASE=$PWD
#####################################################
# Check that jetty is where we think it is
#####################################################
if [ ! -r "$JETTY_HOME/$JETTY_INSTALL_TRACE_FILE" ]
if [ ! -r "$JETTY_HOME/$JETTY_INSTALL_TRACE_FILE" ]
then
echo "** ERROR: Oops! Jetty doesn't appear to be installed in $JETTY_HOME"
echo "** ERROR: $JETTY_HOME/$JETTY_INSTALL_TRACE_FILE is not readable!"
@ -244,7 +244,7 @@ fi
# but only if no configurations were given on the
# command line.
##################################################
if [ -z "$JETTY_CONF" ]
if [ -z "$JETTY_CONF" ]
then
if [ -f $ETC/${NAME}.conf ]
then
@ -261,7 +261,7 @@ fi
#####################################################
# Find a location for the pid file
#####################################################
if [ -z "$JETTY_RUN" ]
if [ -z "$JETTY_RUN" ]
then
JETTY_RUN=$(findDirectory -w /var/run /usr/var/run $JETTY_BASE /tmp)
fi
@ -269,12 +269,12 @@ fi
#####################################################
# Find a pid and state file
#####################################################
if [ -z "$JETTY_PID" ]
if [ -z "$JETTY_PID" ]
then
JETTY_PID="$JETTY_RUN/${NAME}.pid"
fi
if [ -z "$JETTY_STATE" ]
if [ -z "$JETTY_STATE" ]
then
JETTY_STATE=$JETTY_BASE/${NAME}.state
fi
@ -289,7 +289,7 @@ JETTY_ARGS=(${JETTY_ARGS[*]} "jetty.state=$JETTY_STATE")
##################################################
# Get the list of config.xml files from jetty.conf
##################################################
if [ -f "$JETTY_CONF" ] && [ -r "$JETTY_CONF" ]
if [ -f "$JETTY_CONF" ] && [ -r "$JETTY_CONF" ]
then
while read -r CONF
do
@ -297,18 +297,18 @@ then
continue
fi
if [ -d "$CONF" ]
if [ -d "$CONF" ]
then
# assume it's a directory with configure.xml files
# for example: /etc/jetty.d/
# sort the files before adding them to the list of JETTY_ARGS
for XMLFILE in "$CONF/"*.xml
do
if [ -r "$XMLFILE" ] && [ -f "$XMLFILE" ]
if [ -r "$XMLFILE" ] && [ -f "$XMLFILE" ]
then
JETTY_ARGS=(${JETTY_ARGS[*]} "$XMLFILE")
else
echo "** WARNING: Cannot read '$XMLFILE' specified in '$JETTY_CONF'"
echo "** WARNING: Cannot read '$XMLFILE' specified in '$JETTY_CONF'"
fi
done
else
@ -335,11 +335,11 @@ fi
#####################################################
# See if JETTY_LOGS is defined
#####################################################
if [ -z "$JETTY_LOGS" ] && [ -d $JETTY_BASE/logs ]
if [ -z "$JETTY_LOGS" ] && [ -d $JETTY_BASE/logs ]
then
JETTY_LOGS=$JETTY_BASE/logs
fi
if [ -z "$JETTY_LOGS" ] && [ -d $JETTY_HOME/logs ]
if [ -z "$JETTY_LOGS" ] && [ -d $JETTY_HOME/logs ]
then
JETTY_LOGS=$JETTY_HOME/logs
fi
@ -367,7 +367,7 @@ esac
#####################################################
case "`uname`" in
CYGWIN*)
CYGWIN*)
JETTY_HOME="`cygpath -w $JETTY_HOME`"
JETTY_BASE="`cygpath -w $JETTY_BASE`"
TMPDIR="`cygpath -w $TMPDIR`"
@ -397,7 +397,7 @@ RUN_ARGS=(${JAVA_OPTIONS[@]} -jar "$JETTY_START" ${JETTY_ARGS[*]})
RUN_CMD=("$JAVA" ${RUN_ARGS[@]})
#####################################################
# Comment these out after you're happy with what
# Comment these out after you're happy with what
# the script is doing.
#####################################################
if (( DEBUG ))
@ -422,12 +422,12 @@ case "$ACTION" in
start)
echo -n "Starting Jetty: "
if (( NO_START )); then
if (( NO_START )); then
echo "Not starting ${NAME} - NO_START=1";
exit
fi
if [ $UID -eq 0 ] && type start-stop-daemon > /dev/null 2>&1
if [ $UID -eq 0 ] && type start-stop-daemon > /dev/null 2>&1
then
unset CH_USER
if [ -n "$JETTY_USER" ]
@ -487,7 +487,7 @@ case "$ACTION" in
echo -n "Stopping Jetty: "
if [ $UID -eq 0 ] && type start-stop-daemon > /dev/null 2>&1; then
start-stop-daemon -K -p"$JETTY_PID" -d"$JETTY_HOME" -a "$JAVA" -s HUP
TIMEOUT=30
while running "$JETTY_PID"; do
if (( TIMEOUT-- == 0 )); then
@ -508,7 +508,7 @@ case "$ACTION" in
exit 1
fi
kill "$PID" 2>/dev/null
TIMEOUT=30
while running $JETTY_PID; do
if (( TIMEOUT-- == 0 )); then
@ -563,7 +563,13 @@ case "$ACTION" in
;;
check|status)
echo "Checking arguments to Jetty: "
if running "$JETTY_PID"
then
echo "Jetty running pid=$(< "$JETTY_PID")"
else
echo "Jetty NOT running"
fi
echo
echo "START_INI = $START_INI"
echo "START_D = $START_D"
echo "JETTY_HOME = $JETTY_HOME"
@ -579,10 +585,9 @@ case "$ACTION" in
echo "JETTY_ARGS = ${JETTY_ARGS[*]}"
echo "RUN_CMD = ${RUN_CMD[*]}"
echo
if running "$JETTY_PID"
then
echo "Jetty running pid=$(< "$JETTY_PID")"
exit 0
fi
exit 1