| 1 |
#!/bin/sh -e
|
| 2 |
#
|
| 3 |
# /etc/init.d/jetty -- startup script for jetty 6.1.18
|
| 4 |
#
|
| 5 |
# Written by Philipp Meier <meier@meisterbohne.de>
|
| 6 |
# Modified for Jetty 6 by Ludovic Claude <ludovic.claude@laposte.net>
|
| 7 |
#
|
| 8 |
### BEGIN INIT INFO
|
| 9 |
# Provides: jetty
|
| 10 |
# Required-Start: $local_fs $remote_fs $network
|
| 11 |
# Required-Stop: $local_fs $remote_fs $network
|
| 12 |
# Should-Start: $named
|
| 13 |
# Should-Stop: $named
|
| 14 |
# Default-Start: 2 3 4 5
|
| 15 |
# Default-Stop: 0 1 6
|
| 16 |
# Short-Description: Start Jetty
|
| 17 |
# Description: Start Jetty HTTP server and servlet container.
|
| 18 |
### END INIT INFO
|
| 19 |
|
| 20 |
# Configuration files
|
| 21 |
#
|
| 22 |
# /etc/default/jetty
|
| 23 |
# If it exists, this is read at the start of script. It may perform any
|
| 24 |
# sequence of shell commands, like setting relevant environment variables.
|
| 25 |
#
|
| 26 |
# /etc/jetty/jetty.conf
|
| 27 |
# If found, the file will be used as this script's configuration.
|
| 28 |
# Each line in the file may contain:
|
| 29 |
# - A comment denoted by the pound (#) sign as first non-blank character.
|
| 30 |
# - The path to a regular file, which will be passed to jetty as a
|
| 31 |
# config.xml file.
|
| 32 |
# - The path to a directory. Each *.xml file in the directory will be
|
| 33 |
# passed to jetty as a config.xml file.
|
| 34 |
#
|
| 35 |
# The files will be checked for existence before being passed to jetty.
|
| 36 |
#
|
| 37 |
# /etc/jetty/jetty.xml
|
| 38 |
# If found, used as this script's configuration file, but only if
|
| 39 |
# /etc/jetty/jetty.conf was not present. See above.
|
| 40 |
#
|
| 41 |
# Configuration variables (to define in /etc/default/jetty)
|
| 42 |
#
|
| 43 |
# JAVA_HOME
|
| 44 |
# Home of Java installation.
|
| 45 |
#
|
| 46 |
# JAVA
|
| 47 |
# Command to invoke Java. If not set, $JAVA_HOME/bin/java will be
|
| 48 |
# used.
|
| 49 |
#
|
| 50 |
# JAVA_OPTIONS
|
| 51 |
# Extra options to pass to the JVM
|
| 52 |
#
|
| 53 |
# JETTY_PORT
|
| 54 |
# Override the default port for Jetty servers. If not set then 8080
|
| 55 |
# will be used. The java system property "jetty.port" will be set to
|
| 56 |
# this value for use in configure.xml files. For example, the following
|
| 57 |
# idiom is widely used in the demo config files to respect this property
|
| 58 |
# in Listener configuration elements:
|
| 59 |
#
|
| 60 |
# <Set name="Port"><SystemProperty name="jetty.port" default="8080"/></Set>
|
| 61 |
#
|
| 62 |
# JETTY_ARGS
|
| 63 |
# The default arguments to pass to jetty.
|
| 64 |
#
|
| 65 |
# JETTY_USER
|
| 66 |
# if set, then used as a username to run the server as
|
| 67 |
|
| 68 |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
| 69 |
NAME=jetty
|
| 70 |
DESC="Jetty servlet engine"
|
| 71 |
JETTY_HOME=/usr/share/$NAME
|
| 72 |
LOGDIR="/var/log/jetty"
|
| 73 |
START_JAR="$JETTY_HOME/start.jar"
|
| 74 |
START_DAEMON_JAR="$JETTY_HOME/start-daemon.jar"
|
| 75 |
DEFAULT=/etc/default/$NAME
|
| 76 |
DAEMON=/usr/bin/jsvc
|
| 77 |
JVM_TMP=/var/cache/jetty/tmp
|
| 78 |
|
| 79 |
if [ `id -u` -ne 0 ]; then
|
| 80 |
echo "You need root privileges to run this script"
|
| 81 |
exit 1
|
| 82 |
fi
|
| 83 |
|
| 84 |
# Make sure jetty is started with system locale
|
| 85 |
if [ -r /etc/default/locale ]; then
|
| 86 |
. /etc/default/locale
|
| 87 |
export LANG
|
| 88 |
fi
|
| 89 |
|
| 90 |
. /lib/lsb/init-functions
|
| 91 |
|
| 92 |
if [ -r /etc/default/rcS ]; then
|
| 93 |
. /etc/default/rcS
|
| 94 |
fi
|
| 95 |
|
| 96 |
|
| 97 |
# The following variables can be overwritten in /etc/default/jetty
|
| 98 |
|
| 99 |
# Whether to start jetty (as a daemon) or not
|
| 100 |
NO_START=0
|
| 101 |
|
| 102 |
# Run Jetty as this user ID (default: jetty)
|
| 103 |
# Set this to an empty string to prevent Jetty from starting automatically
|
| 104 |
JETTY_USER=jetty
|
| 105 |
|
| 106 |
# Listen to connections from this network host (leave empty to accept all connections)
|
| 107 |
#JETTY_HOST=$(uname -n)
|
| 108 |
JETTY_HOST=
|
| 109 |
|
| 110 |
# The network port used by Jetty
|
| 111 |
JETTY_PORT=8080
|
| 112 |
|
| 113 |
# Additional arguments to pass to Jetty
|
| 114 |
JETTY_ARGS=
|
| 115 |
|
| 116 |
# Extra options to pass to the JVM
|
| 117 |
# Set java.awt.headless=true if JAVA_OPTIONS is not set so the
|
| 118 |
# Xalan XSL transformer can work without X11 display on JDK 1.4+
|
| 119 |
# It also sets the maximum heap size to 256M to deal with most cases.
|
| 120 |
JAVA_OPTIONS="-Xmx256m -Djava.awt.headless=true"
|
| 121 |
|
| 122 |
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
|
| 123 |
# defined in /etc/default/jetty). Should contain a list of space separated directories.
|
| 124 |
JDK_DIRS="
|
| 125 |
/usr/lib/jvm/default-java \
|
| 126 |
/usr/lib/jvm/java-6-sun \
|
| 127 |
/usr/lib/jvm/java-6-openjdk \
|
| 128 |
/usr/lib/jvm/java-1.5.0-sun \
|
| 129 |
/usr/lib/jvm/java-gcj \
|
| 130 |
/usr/lib/j2sdk1.6-sun \
|
| 131 |
/usr/lib/j2sdk1.5-sun \
|
| 132 |
/usr/lib/j2sdk1.5-ibm \
|
| 133 |
/usr/lib/j2sdk1.4-sun \
|
| 134 |
/usr/lib/j2sdk1.4 \
|
| 135 |
/usr/lib/j2se/1.4 \
|
| 136 |
/usr/lib/kaffe/ \
|
| 137 |
"
|
| 138 |
|
| 139 |
# Timeout in seconds for the shutdown of all webapps
|
| 140 |
JETTY_SHUTDOWN=30
|
| 141 |
|
| 142 |
# Jetty uses a directory to store temporary files like unpacked webapps
|
| 143 |
JETTY_TMP=/var/cache/jetty/data
|
| 144 |
|
| 145 |
# Jetty uses a config file to setup its boot classpath
|
| 146 |
JETTY_START_CONFIG=/etc/jetty/start.config
|
| 147 |
|
| 148 |
# End of variables that can be overwritten in /etc/default/jetty
|
| 149 |
|
| 150 |
# overwrite settings from default file
|
| 151 |
if [ -f "$DEFAULT" ]; then
|
| 152 |
. "$DEFAULT"
|
| 153 |
fi
|
| 154 |
|
| 155 |
# Check whether jetty is still installed (it might not be if this package was
|
| 156 |
# removed and not purged)
|
| 157 |
if [ ! -r "$START_JAR" ]; then
|
| 158 |
log_failure_msg "$NAME is not installed"
|
| 159 |
exit 1
|
| 160 |
fi
|
| 161 |
|
| 162 |
[ -f "$DAEMON" ] || exit 0
|
| 163 |
|
| 164 |
# Check whether startup has been disabled
|
| 165 |
if [ "$NO_START" != "0" -a "$1" != "stop" ]; then
|
| 166 |
[ "$VERBOSE" != "no" ] && log_failure_msg "Not starting jetty - edit /etc/default/jetty and change NO_START to be 0 (or comment it out)."
|
| 167 |
exit 0
|
| 168 |
fi
|
| 169 |
|
| 170 |
if [ -z "$JETTY_USER" ]; then
|
| 171 |
log_failure_msg "Not starting/stopping $DESC as configured"
|
| 172 |
log_failure_msg "(JETTY_USER is empty in /etc/default/jetty)."
|
| 173 |
exit 0
|
| 174 |
fi
|
| 175 |
|
| 176 |
# Look for the right JVM to use
|
| 177 |
for jdir in $JDK_DIRS; do
|
| 178 |
if [ -d "$jdir" -a -z "${JAVA_HOME}" ]; then
|
| 179 |
JAVA_HOME="$jdir"
|
| 180 |
fi
|
| 181 |
done
|
| 182 |
export JAVA_HOME
|
| 183 |
|
| 184 |
export JAVA="$JAVA_HOME/bin/java"
|
| 185 |
|
| 186 |
JAVA_OPTIONS="$JAVA_OPTIONS -Djava.io.tmpdir=$JETTY_TMP \
|
| 187 |
-Djava.library.path=/usr/lib -DSTART=$JETTY_START_CONFIG \
|
| 188 |
-Djetty.home=$JETTY_HOME -Djetty.logs=$LOGDIR \
|
| 189 |
-Djetty.host=$JETTY_HOST -Djetty.port=$JETTY_PORT"
|
| 190 |
|
| 191 |
# Set the JSP compiler if set in the jetty.default file
|
| 192 |
if [ -n "$JSP_COMPILER" ]; then
|
| 193 |
JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=$JSP_COMPILER"
|
| 194 |
fi
|
| 195 |
|
| 196 |
export JAVA_OPTIONS
|
| 197 |
|
| 198 |
# Define other required variables
|
| 199 |
PIDFILE="/var/run/$NAME.pid"
|
| 200 |
WEBAPPDIR="$JETTY_HOME/webapps"
|
| 201 |
BOOTSTRAP_CLASS=org.mortbay.jetty.start.daemon.Bootstrap
|
| 202 |
JSVC_CLASSPATH="/usr/share/java/commons-daemon.jar:$START_JAR:$START_DAEMON_JAR:$JAVA_HOME/lib/tools.jar"
|
| 203 |
ROTATELOGS=/usr/sbin/rotatelogs
|
| 204 |
HOSTNAME=$(uname -n)
|
| 205 |
|
| 206 |
##################################################
|
| 207 |
# Check for JAVA_HOME
|
| 208 |
##################################################
|
| 209 |
if [ -z "$JAVA_HOME" ]; then
|
| 210 |
log_failure_msg "Could not start $DESC because no Java Development Kit"
|
| 211 |
log_failure_msg "(JDK) was found. Please download and install JDK 1.4 or higher and set"
|
| 212 |
log_failure_msg "JAVA_HOME in /etc/default/jetty to the JDK's installation directory."
|
| 213 |
exit 0
|
| 214 |
fi
|
| 215 |
|
| 216 |
CONFIG_LINES=$(cat /etc/jetty/jetty.conf | grep -v "^[:space:]*#" | tr "\n" " ")
|
| 217 |
|
| 218 |
##################################################
|
| 219 |
# Get the list of config.xml files from jetty.conf
|
| 220 |
##################################################
|
| 221 |
if [ ! -z "${CONFIG_LINES}" ]
|
| 222 |
then
|
| 223 |
for CONF in ${CONFIG_LINES}
|
| 224 |
do
|
| 225 |
if [ ! -r "$CONF" ]
|
| 226 |
then
|
| 227 |
log_warning_msg "WARNING: Cannot read '$CONF' specified in '$JETTY_CONF'"
|
| 228 |
elif [ -f "$CONF" ]
|
| 229 |
then
|
| 230 |
# assume it's a configure.xml file
|
| 231 |
CONFIGS="$CONFIGS $CONF"
|
| 232 |
elif [ -d "$CONF" ]
|
| 233 |
then
|
| 234 |
# assume it's a directory with configure.xml files
|
| 235 |
# for example: /etc/jetty.d/
|
| 236 |
# sort the files before adding them to the list of CONFIGS
|
| 237 |
XML_FILES=`ls ${CONF}/*.xml | sort | tr "\n" " "`
|
| 238 |
for FILE in ${XML_FILES}
|
| 239 |
do
|
| 240 |
if [ -r "$FILE" ] && [ -f "$FILE" ]
|
| 241 |
then
|
| 242 |
CONFIGS="$CONFIGS $FILE"
|
| 243 |
else
|
| 244 |
log_warning_msg "WARNING: Cannot read '$FILE' specified in '$JETTY_CONF'"
|
| 245 |
fi
|
| 246 |
done
|
| 247 |
else
|
| 248 |
log_warning_msg "WARNING: Don''t know what to do with '$CONF' specified in '$JETTY_CONF'"
|
| 249 |
fi
|
| 250 |
done
|
| 251 |
fi
|
| 252 |
|
| 253 |
#####################################################
|
| 254 |
# Run the standard server if there's nothing else to run
|
| 255 |
#####################################################
|
| 256 |
if [ -z "$CONFIGS" ]
|
| 257 |
then
|
| 258 |
CONFIGS="/etc/jetty/jetty-logging.xml /etc/jetty/jetty.xml"
|
| 259 |
fi
|
| 260 |
|
| 261 |
##################################################
|
| 262 |
# Do the action
|
| 263 |
##################################################
|
| 264 |
case "$1" in
|
| 265 |
start)
|
| 266 |
log_daemon_msg "Starting $DESC." "$NAME"
|
| 267 |
if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
|
| 268 |
--user "$JETTY_USER" --startas "$JAVA" > /dev/null; then
|
| 269 |
|
| 270 |
if [ -f $PIDFILE ]
|
| 271 |
then
|
| 272 |
log_warning_msg "$PIDFILE exists, but jetty was not running. Ignoring $PIDFILE"
|
| 273 |
fi
|
| 274 |
|
| 275 |
if [ \! -e "$LOGDIR/out.log" ]; then
|
| 276 |
log_progress_msg "Create log file"
|
| 277 |
sudo -u $JETTY_USER touch "$LOGDIR/out.log"
|
| 278 |
chown $JETTY_USER:adm "$LOGDIR/out.log"
|
| 279 |
fi
|
| 280 |
log_progress_msg "Rotate logs"
|
| 281 |
sudo -b -u $JETTY_USER $ROTATELOGS "$LOGDIR/out.log" 86400 \
|
| 282 |
< "$LOGDIR/out.log"
|
| 283 |
|
| 284 |
# Remove / recreate JETTY_TMP directory
|
| 285 |
rm -rf "$JETTY_TMP"
|
| 286 |
mkdir "$JETTY_TMP" || {
|
| 287 |
log_failure_msg "could not create $DESC temporary directory at $JETTY_TMP"
|
| 288 |
exit 1
|
| 289 |
}
|
| 290 |
chown $JETTY_USER "$JETTY_TMP"
|
| 291 |
|
| 292 |
# Remove / recreate JVM_TMP directory
|
| 293 |
rm -rf "$JVM_TMP"
|
| 294 |
mkdir "$JVM_TMP" || {
|
| 295 |
log_failure_msg "could not create JVM temporary directory at $JVM_TMP"
|
| 296 |
exit 1
|
| 297 |
}
|
| 298 |
chown $JETTY_USER "$JVM_TMP"
|
| 299 |
cd "$JVM_TMP"
|
| 300 |
|
| 301 |
$DAEMON -user "$JETTY_USER" -cp "$JSVC_CLASSPATH" \
|
| 302 |
-outfile $LOGDIR/out.log -errfile $LOGDIR/out.log \
|
| 303 |
-pidfile "$PIDFILE" $JAVA_OPTIONS $BOOTSTRAP_CLASS \
|
| 304 |
$JETTY_ARGS $CONFIGS
|
| 305 |
|
| 306 |
log_daemon_msg "$DESC started, reachable on http://$HOSTNAME:$JETTY_PORT/." "$NAME"
|
| 307 |
|
| 308 |
sleep 5
|
| 309 |
if start-stop-daemon --test --start --pidfile "$PIDFILE" \
|
| 310 |
--user $JETTY_USER --startas "$JAVA" >/dev/null; then
|
| 311 |
log_end_msg 1
|
| 312 |
else
|
| 313 |
log_end_msg 0
|
| 314 |
fi
|
| 315 |
|
| 316 |
else
|
| 317 |
log_warning_msg "(already running)."
|
| 318 |
log_end_msg 0
|
| 319 |
exit 1
|
| 320 |
fi
|
| 321 |
;;
|
| 322 |
|
| 323 |
stop)
|
| 324 |
log_daemon_msg "Stopping $DESC (was reachable on http://$HOSTNAME:$JETTY_PORT/)." "$NAME"
|
| 325 |
|
| 326 |
if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
|
| 327 |
--user "$JETTY_USER" --startas "$JAVA" > /dev/null; then
|
| 328 |
if [ -x "$PIDFILE" ]; then
|
| 329 |
log_warning_msg "(not running but $PIDFILE exists)."
|
| 330 |
else
|
| 331 |
log_warning_msg "(not running)."
|
| 332 |
fi
|
| 333 |
else
|
| 334 |
start-stop-daemon --quiet --stop \
|
| 335 |
--pidfile "$PIDFILE" --user "$JETTY_USER" \
|
| 336 |
--startas "$JAVA" > /dev/null
|
| 337 |
while ! start-stop-daemon --quiet --test --start \
|
| 338 |
--pidfile "$PIDFILE" --user "$JETTY_USER" \
|
| 339 |
--startas "$JAVA" > /dev/null; do
|
| 340 |
sleep 1
|
| 341 |
log_progress_msg "."
|
| 342 |
JETTY_SHUTDOWN=`expr $JETTY_SHUTDOWN - 1` || true
|
| 343 |
if [ $JETTY_SHUTDOWN -ge 0 ]; then
|
| 344 |
start-stop-daemon --oknodo --quiet --stop \
|
| 345 |
--pidfile "$PIDFILE" --user "$JETTY_USER" \
|
| 346 |
--startas "$JAVA"
|
| 347 |
else
|
| 348 |
log_progress_msg " (killing) "
|
| 349 |
start-stop-daemon --stop --signal 9 --oknodo \
|
| 350 |
--quiet --pidfile "$PIDFILE" \
|
| 351 |
--user "$JETTY_USER"
|
| 352 |
fi
|
| 353 |
done
|
| 354 |
rm -f "$PIDFILE"
|
| 355 |
rm -rf "$JVM_TMP"
|
| 356 |
rm -rf "$JETTY_TMP/*"
|
| 357 |
log_daemon_msg "$DESC stopped." "$NAME"
|
| 358 |
log_end_msg 0
|
| 359 |
fi
|
| 360 |
;;
|
| 361 |
|
| 362 |
status)
|
| 363 |
if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
|
| 364 |
--user "$JETTY_USER" --startas "$JAVA" > /dev/null; then
|
| 365 |
|
| 366 |
if [ -f "$PIDFILE" ]; then
|
| 367 |
log_success_msg "$DESC is not running, but pid file exists."
|
| 368 |
exit 1
|
| 369 |
else
|
| 370 |
log_success_msg "$DESC is not running."
|
| 371 |
exit 3
|
| 372 |
fi
|
| 373 |
else
|
| 374 |
log_success_msg "$DESC is running with pid `cat $PIDFILE`, and is reachable on http://$JETTY_HOST:$JETTY_PORT/"
|
| 375 |
fi
|
| 376 |
;;
|
| 377 |
|
| 378 |
restart|force-reload)
|
| 379 |
if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
|
| 380 |
--user "$JETTY_USER" --startas "$JAVA" > /dev/null; then
|
| 381 |
$0 stop $*
|
| 382 |
sleep 1
|
| 383 |
fi
|
| 384 |
$0 start $*
|
| 385 |
;;
|
| 386 |
|
| 387 |
try-restart)
|
| 388 |
if start-stop-daemon --quiet --test --start --pidfile "$PIDFILE" \
|
| 389 |
--user "$JETTY_USER" --startas "$JAVA" > /dev/null; then
|
| 390 |
$0 start $*
|
| 391 |
fi
|
| 392 |
;;
|
| 393 |
|
| 394 |
check)
|
| 395 |
log_success_msg "Checking arguments for Jetty: "
|
| 396 |
log_success_msg ""
|
| 397 |
log_success_msg "PIDFILE = $PIDFILE"
|
| 398 |
log_success_msg "JAVA_OPTIONS = $JAVA_OPTIONS"
|
| 399 |
log_success_msg "JAVA = $JAVA"
|
| 400 |
log_success_msg "JETTY_USER = $JETTY_USER"
|
| 401 |
log_success_msg "JETTY_HOST = $JETTY_HOST"
|
| 402 |
log_success_msg "JETTY_PORT = $JETTY_PORT"
|
| 403 |
log_success_msg "ARGUMENTS = $ARGUMENTS"
|
| 404 |
|
| 405 |
if [ -f $PIDFILE ]
|
| 406 |
then
|
| 407 |
log_success_msg "$DESC is running with pid `cat $PIDFILE`, and is reachable on http://$JETTY_HOST:$JETTY_PORT/"
|
| 408 |
exit 0
|
| 409 |
fi
|
| 410 |
exit 1
|
| 411 |
;;
|
| 412 |
|
| 413 |
*)
|
| 414 |
log_success_msg "Usage: $0 {start|stop|restart|force-reload|try-restart|status|check}"
|
| 415 |
exit 1
|
| 416 |
;;
|
| 417 |
esac
|
| 418 |
|
| 419 |
exit 0
|