<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<!-- =============================================================== -->
<!-- Create the deployment manager -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- The deplyment manager handles the lifecycle of deploying web -->
<!-- applications. Apps are provided by instances of the -->
<!-- AppProvider interface. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addBean">
<Arg>
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
<Set name="contexts">
<Ref refid="Contexts" />
</Set>
<Call name="setContextAttribute">
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
<Arg>.*/servlet-api-[^/]*\.jar$</Arg>
</Call>
<!-- Add a customize step to the deployment lifecycle -->
<!-- uncomment and replace DebugBinding with your extended AppLifeCycle.Binding class
<Call name="insertLifeCycleNode">
<Arg>deployed</Arg>
<Arg>starting</Arg>
<Arg>customise</Arg>
</Call>
<Call name="addLifeCycleBinding">
<Arg>
<New class="org.eclipse.jetty.deploy.bindings.DebugBinding">
<Arg>customise</Arg>
</New>
</Arg>
</Call> -->
<Call id="webappprovider" name="addAppProvider">
<Arg>
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
<Set name="monitoredDirName"><Property name="jetty.webapps"/></Set>
<Set name="defaultsDescriptor"><Property name="jetty.home" default="." />/etc/webdefault.xml</Set>
<Set name="scanInterval">0</Set>
<Set name="extractWars">true</Set>
<Set name="configurationManager">
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager"></New>
</Set>
</New>
</Arg>
</Call>
</New>
</Arg>
</Call>
</Configure>
<?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><Property name="jetty.state"/></Arg>
</New>
</Arg>
</Call>
</Configure>
#!/usr/bin/env bash
#Author Simon
# set profile
source ~/.bash_profile
# set project directory
if [ -z "$PROJECT_HOME" ]
then
START_SH=$0
case "$START_SH" in
/*) PROJECT_HOME=${START_SH%/*} ;;
./*/*/*) PROJECT_HOME=${START_SH%/*} ;;
./*) PROJECT_HOME=. ;;
esac
fi
cd "$PROJECT_HOME"
PROJECT_HOME=$PWD
# set jetty home directory
JETTY_HOME=${PROJECT_HOME%/*/*}
cd "$JETTY_HOME"
# create project log directory
logDir="$PROJECT_HOME/log"
if [ ! -d ${logDir} ]
then
$(mkdir -p ${logDir})
fi
# create project data directory
dataDir="$PROJECT_HOME/data"
if [ ! -d ${dataDir} ]
then
$(mkdir -p ${dataDir})
fi
source "$PROJECT_HOME/server.conf"
# jetty status
if [ -z "$JETTY_STATE" ]
then
JETTY_STATE=$dataDir/jetty.state
fi
rm -f $JETTY_STATE
if [ -z "$JAVA" ]
then
JAVA=$(which java)
fi
# Add jetty properties to Java VM options.
TMPDIR=${TMPDIR:-/tmp}
JAVA_OPTIONS+=("-Djetty.home=$JETTY_HOME" "-Djava.io.tmpdir=$TMPDIR")
# This is how the Jetty server will be started
JETTY_START=$JETTY_HOME/start.jar
[ ! -f "$JETTY_START" ] && JETTY_START=$JETTY_HOME/lib/start.jar
START_INI=$(dirname $JETTY_START)/start.ini
[ -r "$START_INI" ] || START_INI=""
CONFIGS=(
${JETTY_HOME}/etc/jetty-logging.xml
${PROJECT_HOME}/etc/jetty-deploy.xml
${PROJECT_HOME}/etc/jetty-started.xml
)
JETTY_ARGS=(
"jetty.logs"=${PROJECT_HOME}/log
"jetty.webapps"=${PROJECT_HOME}/webapps
"jetty.state"=${JETTY_STATE}
)
usage()
{
echo "Usage: ${0##*/} {start|stop|switch}"
exit 1
}
[ $# -gt 0 ] || usage
isRun()
{
kill -0 "$1" 2>/dev/null
}
getPid()
{
echo $(cut -d\| -f 1 ${dataDir}/project_$1.pid 2>/dev/null)
}
#引用自jetty.sh
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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
do
sleep 4
[ -z "$(grep STARTED $1 2>/dev/null)" ] || return 0
[ -z "$(grep STOPPED $1 2>/dev/null)" ] || return 1
[ -z "$(grep FAILED $1 2>/dev/null)" ] || return 1
local PID=$2 || return 1
kill -0 "$PID" 2>/dev/null || return 1
echo -n "."
done
return 1
}
shutdownServer()
{
PID=$1
if isRun $PID
then
kill "$PID" 2>/dev/null
TIMEOUT=30
while isRun $PID; do
if (( TIMEOUT-- == 0 )); then
kill -KILL "$PID" 2>/dev/null
fi
sleep 1
done
if ! isRun $PID
then
return 0
else
return 1
fi
fi
return 0
}
start()
{
local currentPort
local port=$1
if [ $port > 0 ]
then
currentPort=$port
else
currentPort=${PORT[0]}
fi
pidFilePath=${dataDir}/project_${currentPort}.pid
PID=$(getPid $currentPort)
if isRun $PID
then
echo "jetty already running!"
exit
fi
#此处限制访问IP为内网
RUN_ARGS=(${JAVA_OPTIONS[@]} -jar "$JETTY_START" ${JETTY_ARGS[@]} jetty.host="10.207.169.50" jetty.port=${currentPort} "${CONFIGS[@]}")
RUN_CMD=("$JAVA" ${RUN_ARGS[@]})
#start jetty
echo "${RUN_CMD[@]}"
"${RUN_CMD[@]}">/dev/null &
JETTY_PID=$!
disown $!
if started "$JETTY_STATE" "$JETTY_PID"
then
echo ""
echo "OK `date`"
else
echo ""
echo "FAILED `date`"
fi
if ! isRun $JETTY_PID
then
echo "jetty run fail!"
exit
fi
echo "Ok! new server startup, PID:[$JETTY_PID], PORT:[$currentPort]"
echo "$JETTY_PID|$currentPort" > $pidFilePath
}
stop()
{
for port in ${PORT[@]}
do
PID=$(getPid $port)
if isRun $PID
then
shutdownServer $PID
if ! isRun $PID
then
closeFlag=1
echo "Ok! PORT:[$port]"
fi
fi
done
if [ ! $closeFlag ]
then
echo "stop fail(not pid file | not start)"
fi
}
switch()
{
for port in ${PORT[@]}
do
local pid=$(getPid $port)
if isRun $pid
then
alreadyStartPort=$port
fi
done
if [ ! $alreadyStartPort ]
then
echo "jetty not start!"
exit
fi
local pid=$(getPid $alreadyStartPort)
echo "current running PID:[$pid], PORT:[$alreadyStartPort]"
for item in ${PORT[@]}
do
if ((item != $alreadyStartPort))
then
#启动此端口的服务
echo "start another jetty PORT:[$item]"
start $item
sleep 2
if shutdownServer $pid
then
echo "Ok! old server shutdown, PID:[$pid], PORT:[$alreadyStartPort]"
else
echo "fail! server shutdown, PID:[$pid], PORT:[$alreadyStartPort]"
fi
fi
done
}
case "$1" in
start)
echo "Starting Jetty..."
start
echo "End"
;;
stop)
echo "Stopping Jetty..."
stop
echo "End"
;;
switch)
echo "Switching Jetty..."
switch
echo "End"
;;
esac
exit 0
--exec
-Xmx4096m
-Xms4096m
-Xmn1536m
-XX:PermSize=512m
-XX:MaxPermSize=512m
-XX:MaxTenuringThreshold=7
-XX:GCTimeRatio=19
-XX:+UseConcMarkSweepGC
-XX:ParallelGCThreads=8
-XX:+CMSClassUnloadingEnabled
-XX:+UseCMSCompactAtFullCollection
-XX:CMSFullGCsBeforeCompaction=5
-XX:-CMSParallelRemarkEnabled
-XX:+DisableExplicitGC
-XX:CMSInitiatingOccupancyFraction=40
-XX:SoftRefLRUPolicyMSPerMB=0
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-Xloggc:logs/gc.log