403281 jetty.sh waits for started before OK
This commit is contained in:
parent
29b83dff9b
commit
a7238f2688
|
@ -106,10 +106,24 @@ findDirectory()
|
||||||
|
|
||||||
running()
|
running()
|
||||||
{
|
{
|
||||||
local PID=$(cat "$1" 2>/dev/null) || return 1
|
local PID=$(head -n 1 "$1" 2>/dev/null) || return 1
|
||||||
kill -0 "$PID" 2>/dev/null
|
kill -0 "$PID" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
do
|
||||||
|
sleep 4
|
||||||
|
[ -z "$(grep STARTED $1)" ] || return 0
|
||||||
|
echo -n ". "
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
readConfig()
|
readConfig()
|
||||||
{
|
{
|
||||||
(( DEBUG )) && echo "Reading $1.."
|
(( DEBUG )) && echo "Reading $1.."
|
||||||
|
@ -137,7 +151,13 @@ shift
|
||||||
##################################################
|
##################################################
|
||||||
# Read any configuration files
|
# Read any configuration files
|
||||||
##################################################
|
##################################################
|
||||||
for CONFIG in /etc/default/jetty{,9} $HOME/.jettyrc; do
|
ETC=/etc
|
||||||
|
if [ $UID != 0 ]
|
||||||
|
then
|
||||||
|
ETC=$HOME/etc
|
||||||
|
fi
|
||||||
|
|
||||||
|
for CONFIG in $ETC/default/jetty{,9} $HOME/.jettyrc; do
|
||||||
if [ -f "$CONFIG" ] ; then
|
if [ -f "$CONFIG" ] ; then
|
||||||
readConfig "$CONFIG"
|
readConfig "$CONFIG"
|
||||||
fi
|
fi
|
||||||
|
@ -262,9 +282,9 @@ fi
|
||||||
##################################################
|
##################################################
|
||||||
if [ -z "$JETTY_CONF" ]
|
if [ -z "$JETTY_CONF" ]
|
||||||
then
|
then
|
||||||
if [ -f /etc/jetty.conf ]
|
if [ -f $ETC/jetty.conf ]
|
||||||
then
|
then
|
||||||
JETTY_CONF=/etc/jetty.conf
|
JETTY_CONF=$ETC/jetty.conf
|
||||||
elif [ -f "$JETTY_HOME/etc/jetty.conf" ]
|
elif [ -f "$JETTY_HOME/etc/jetty.conf" ]
|
||||||
then
|
then
|
||||||
JETTY_CONF=$JETTY_HOME/etc/jetty.conf
|
JETTY_CONF=$JETTY_HOME/etc/jetty.conf
|
||||||
|
@ -318,6 +338,7 @@ if [ -z "$JETTY_PID" ]
|
||||||
then
|
then
|
||||||
JETTY_PID="$JETTY_RUN/jetty.pid"
|
JETTY_PID="$JETTY_RUN/jetty.pid"
|
||||||
fi
|
fi
|
||||||
|
JAVA_OPTIONS+=("-Djetty.pid=$JETTY_PID")
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# Setup JAVA if unset
|
# Setup JAVA if unset
|
||||||
|
@ -407,23 +428,15 @@ case "$ACTION" in
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type start-stop-daemon > /dev/null 2>&1
|
if [ $UID -eq 0 ] && type start-stop-daemon > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
unset CH_USER
|
unset CH_USER
|
||||||
if [ -n "$JETTY_USER" ]
|
if [ -n "$JETTY_USER" ]
|
||||||
then
|
then
|
||||||
CH_USER="-c$JETTY_USER"
|
CH_USER="-c$JETTY_USER"
|
||||||
fi
|
fi
|
||||||
if start-stop-daemon -S -p"$JETTY_PID" $CH_USER -d"$JETTY_HOME" -b -m -a "$JAVA" -- "${RUN_ARGS[@]}" --daemon
|
|
||||||
then
|
start-stop-daemon -S -p"$JETTY_PID" $CH_USER -d"$JETTY_HOME" -b -m -a "$JAVA" -- "${RUN_ARGS[@]}" --daemon
|
||||||
sleep 1
|
|
||||||
if running "$JETTY_PID"
|
|
||||||
then
|
|
||||||
echo "OK"
|
|
||||||
else
|
|
||||||
echo "FAILED"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
@ -454,14 +467,20 @@ case "$ACTION" in
|
||||||
echo $! > "$JETTY_PID"
|
echo $! > "$JETTY_PID"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "STARTED Jetty `date`"
|
fi
|
||||||
|
|
||||||
|
if started "$JETTY_PID"
|
||||||
|
then
|
||||||
|
echo "OK `date`"
|
||||||
|
else
|
||||||
|
echo "FAILED `date`"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
stop)
|
stop)
|
||||||
echo -n "Stopping Jetty: "
|
echo -n "Stopping Jetty: "
|
||||||
if type start-stop-daemon > /dev/null 2>&1; then
|
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
|
start-stop-daemon -K -p"$JETTY_PID" -d"$JETTY_HOME" -a "$JAVA" -s HUP
|
||||||
|
|
||||||
TIMEOUT=30
|
TIMEOUT=30
|
||||||
|
@ -476,7 +495,7 @@ case "$ACTION" in
|
||||||
rm -f "$JETTY_PID"
|
rm -f "$JETTY_PID"
|
||||||
echo OK
|
echo OK
|
||||||
else
|
else
|
||||||
PID=$(cat "$JETTY_PID" 2>/dev/null)
|
PID=$(head -n 1 "$JETTY_PID" 2>/dev/null)
|
||||||
kill "$PID" 2>/dev/null
|
kill "$PID" 2>/dev/null
|
||||||
|
|
||||||
TIMEOUT=30
|
TIMEOUT=30
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
|
||||||
|
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<!-- Mixin the Start FileNoticeLifeCycleListener -->
|
||||||
|
<!-- =============================================================== -->
|
||||||
|
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||||
|
<Call name="addLifeCycleListener">
|
||||||
|
<Arg>
|
||||||
|
<New class="org.eclipse.jetty.util.component.FileNoticeLifeCycleListener">
|
||||||
|
<Arg><SystemProperty name="jetty.pid" default="./jetty.pid"/></Arg>
|
||||||
|
</New>
|
||||||
|
</Arg>
|
||||||
|
</Call>
|
||||||
|
</Configure>
|
|
@ -6,8 +6,7 @@
|
||||||
# created by that script.
|
# created by that script.
|
||||||
#
|
#
|
||||||
# Each line in this file becomes an arguement to start.jar
|
# Each line in this file becomes an arguement to start.jar
|
||||||
# unless this file contains an --ini option, then these
|
# in addition to those found in the start.ini file
|
||||||
# arguments will be in addition to those found in the
|
|
||||||
# start.ini file
|
|
||||||
# =======================================================
|
# =======================================================
|
||||||
--pre=etc/jetty-logging.xml
|
etc/jetty-logging.xml
|
||||||
|
etc/jetty-started.xml
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
//
|
||||||
|
// ========================================================================
|
||||||
|
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// All rights reserved. This program and the accompanying materials
|
||||||
|
// are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
// and Apache License v2.0 which accompanies this distribution.
|
||||||
|
//
|
||||||
|
// The Eclipse Public License is available at
|
||||||
|
// http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
//
|
||||||
|
// The Apache License v2.0 is available at
|
||||||
|
// http://www.opensource.org/licenses/apache2.0.php
|
||||||
|
//
|
||||||
|
// You may elect to redistribute this code under either of these licenses.
|
||||||
|
// ========================================================================
|
||||||
|
//
|
||||||
|
|
||||||
|
package org.eclipse.jetty.util.component;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
/** A LifeCycle Listener that writes state changes to a file.
|
||||||
|
* <p>This can be used with the jetty.sh script to wait for successful startup.
|
||||||
|
*/
|
||||||
|
public class FileNoticeLifeCycleListener implements LifeCycle.Listener
|
||||||
|
{
|
||||||
|
Logger LOG = Log.getLogger(FileNoticeLifeCycleListener.class);
|
||||||
|
|
||||||
|
private final String _filename;
|
||||||
|
|
||||||
|
public FileNoticeLifeCycleListener(String filename)
|
||||||
|
{
|
||||||
|
_filename=filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeState(String action, LifeCycle lifecycle)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileWriter out = new FileWriter(_filename,true);
|
||||||
|
out.append(action).append(" ").append(lifecycle.toString()).append("\n");
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
LOG.warn(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lifeCycleStarting(LifeCycle event)
|
||||||
|
{
|
||||||
|
writeState("STARTING",event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lifeCycleStarted(LifeCycle event)
|
||||||
|
{
|
||||||
|
writeState("STARTED",event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lifeCycleFailure(LifeCycle event, Throwable cause)
|
||||||
|
{
|
||||||
|
writeState("FAILED",event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lifeCycleStopping(LifeCycle event)
|
||||||
|
{
|
||||||
|
writeState("STOPPING",event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void lifeCycleStopped(LifeCycle event)
|
||||||
|
{
|
||||||
|
writeState("STOPPED",event);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue