|
|
f8369c |
#!/usr/bin/env bash
|
|
|
f8369c |
# Configuration files
|
|
|
f8369c |
#
|
|
|
f8369c |
# /etc/default/jetty
|
|
|
f8369c |
# If it exists, this is read at the start of script. It may perform any
|
|
|
f8369c |
# sequence of shell commands, like setting relevant environment variables.
|
|
|
f8369c |
#
|
|
|
f8369c |
# /etc/jetty.conf
|
|
|
f8369c |
# If found, and no configurations were given on the command line,
|
|
|
f8369c |
# the file will be used as this script's configuration.
|
|
|
f8369c |
# Each line in the file may contain:
|
|
|
f8369c |
# - A comment denoted by the pound (#) sign as first non-blank character.
|
|
|
f8369c |
# - The path to a regular file, which will be passed to jetty as a
|
|
|
f8369c |
# config.xml file.
|
|
|
f8369c |
# - The path to a directory. Each *.xml file in the directory will be
|
|
|
f8369c |
# passed to jetty as a config.xml file.
|
|
|
f8369c |
# - All other lines will be passed, as-is to the start.jar
|
|
|
f8369c |
#
|
|
|
f8369c |
# The files will be checked for existence before being passed to jetty.
|
|
|
f8369c |
#
|
|
|
f8369c |
# Configuration variables
|
|
|
f8369c |
#
|
|
|
f8369c |
# JAVA
|
|
|
f8369c |
# Command to invoke Java. If not set, java (from the PATH) will be used.
|
|
|
f8369c |
#
|
|
|
f8369c |
# JAVA_OPTIONS
|
|
|
f8369c |
# Extra options to pass to the JVM
|
|
|
f8369c |
#
|
|
|
f8369c |
# JETTY_HOME
|
|
|
f8369c |
# Where Jetty is installed. If not set, the script will try go
|
|
|
f8369c |
# guess it by first looking at the invocation path for the script,
|
|
|
f8369c |
# and then by looking in standard locations as $HOME/opt/jetty
|
|
|
f8369c |
# and /opt/jetty. The java system property "jetty.home" will be
|
|
|
f8369c |
# set to this value for use by configure.xml files, f.e.:
|
|
|
f8369c |
#
|
|
|
f8369c |
# <Arg><Property name="jetty.home" default="."/>/webapps/jetty.war</Arg>
|
|
|
f8369c |
#
|
|
|
f8369c |
# JETTY_BASE
|
|
|
f8369c |
# Where your Jetty base directory is. If not set, the value from
|
|
|
f8369c |
# $JETTY_HOME will be used.
|
|
|
f8369c |
#
|
|
|
f8369c |
# JETTY_ARGS
|
|
|
f8369c |
# The default arguments to pass to jetty.
|
|
|
f8369c |
# For example
|
|
|
f8369c |
# JETTY_ARGS=jetty.port=8080 jetty.spdy.port=8443 jetty.secure.port=443
|
|
|
f8369c |
#
|
|
|
f8369c |
|
|
|
f8369c |
set -e -C
|
|
|
f8369c |
|
|
|
f8369c |
readConfig()
|
|
|
f8369c |
{
|
|
|
f8369c |
echo "Reading $1.."
|
|
|
f8369c |
source "$1"
|
|
|
f8369c |
}
|
|
|
f8369c |
|
|
|
f8369c |
CONFIGS=()
|
|
|
f8369c |
|
|
|
f8369c |
if [ -f /etc/default/jetty ]; then
|
|
|
f8369c |
readConfig /etc/default/jetty
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
if [ -z "$JETTY_HOME" ]; then
|
|
|
f8369c |
JETTY_HOME=/usr/share/jetty
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
if [ -z "$JETTY_BASE" ]; then
|
|
|
f8369c |
JETTY_BASE="$JETTY_HOME"
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
cd "$JETTY_BASE"
|
|
|
f8369c |
JETTY_BASE="$PWD"
|
|
|
f8369c |
|
|
|
f8369c |
if [ -z "$JETTY_CONF" ]
|
|
|
f8369c |
then
|
|
|
f8369c |
JETTY_CONF=/etc/jetty.conf
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
if [ -f "$JETTY_CONF" ] && [ -r "$JETTY_CONF" ]
|
|
|
f8369c |
then
|
|
|
f8369c |
while read -r CONF
|
|
|
f8369c |
do
|
|
|
f8369c |
if expr "$CONF" : '#' >/dev/null ; then
|
|
|
f8369c |
continue
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
if [ -d "$CONF" ]
|
|
|
f8369c |
then
|
|
|
f8369c |
# assume it's a directory with configure.xml files
|
|
|
f8369c |
# for example: /etc/jetty.d/
|
|
|
f8369c |
# sort the files before adding them to the list of JETTY_ARGS
|
|
|
f8369c |
for XMLFILE in "$CONF/"*.xml
|
|
|
f8369c |
do
|
|
|
f8369c |
if [ -r "$XMLFILE" ] && [ -f "$XMLFILE" ]
|
|
|
f8369c |
then
|
|
|
f8369c |
JETTY_ARGS+=("$XMLFILE")
|
|
|
f8369c |
else
|
|
|
f8369c |
echo "** WARNING: Cannot read '$XMLFILE' specified in '$JETTY_CONF'"
|
|
|
f8369c |
fi
|
|
|
f8369c |
done
|
|
|
f8369c |
else
|
|
|
f8369c |
# assume it's a command line parameter (let start.jar deal with its validity)
|
|
|
f8369c |
JETTY_ARGS+=("$CONF")
|
|
|
f8369c |
fi
|
|
|
f8369c |
done < "$JETTY_CONF"
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
if [ -z "$JAVA" ]
|
|
|
f8369c |
then
|
|
|
f8369c |
. /usr/share/java-utils/java-functions
|
|
|
f8369c |
set_jvm
|
|
|
f8369c |
set_javacmd
|
|
|
f8369c |
JAVA="$JAVACMD"
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
if [ -z "$JETTY_LOGS" ] && [ -d $JETTY_BASE/logs ]
|
|
|
f8369c |
then
|
|
|
f8369c |
JETTY_LOGS=/var/log/jetty/logs
|
|
|
f8369c |
fi
|
|
|
f8369c |
JAVA_OPTIONS+=("-Djetty.logs=$JETTY_LOGS")
|
|
|
f8369c |
|
|
|
f8369c |
JAVA_OPTIONS+=("-Djetty.home=$JETTY_HOME" "-Djetty.base=$JETTY_BASE")
|
|
|
f8369c |
|
|
|
f8369c |
JETTY_START="$JETTY_HOME/start.jar"
|
|
|
f8369c |
START_INI="$JETTY_BASE/start.ini"
|
|
|
f8369c |
if [ ! -f "$START_INI" ]
|
|
|
f8369c |
then
|
|
|
f8369c |
echo "Cannot find a start.ini in your JETTY_BASE directory: $JETTY_BASE" 2>&2
|
|
|
f8369c |
exit 1
|
|
|
f8369c |
fi
|
|
|
f8369c |
|
|
|
f8369c |
RUN_ARGS=(${JAVA_OPTIONS[@]} -jar "$JETTY_START" ${JETTY_ARGS[*]})
|
|
|
f8369c |
RUN_CMD=("$JAVA" ${RUN_ARGS[@]})
|
|
|
f8369c |
|
|
|
f8369c |
echo -n "Starting Jetty: "
|
|
|
f8369c |
${RUN_CMD[*]}
|