Debian Codegraph @

jetty-home/src/main/resources/bin/jetty.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 # LSB Tags
4 ### BEGIN INIT INFO
5 # Provides: jetty
6 # Required-Start: $local_fs $network
7 # Required-Stop: $local_fs $network
8 # Default-Start: 2 3 4 5
9 # Default-Stop: 0 1 6
10 # Short-Description: Jetty start script.
11 # Description: Start Jetty web server.
12 ### END INIT INFO
13
14 # Startup script for jetty under *nix systems (it works under NT/cygwin too).
15
16 ##################################################
17 # Set the name which is used by other variables.
18 # Defaults to the file name without extension.
19 ##################################################
20 NAME=$(echoscip-shell system . . echo. $(basenamescip-shell system . . basename. $0) | sedscip-shell system . . sed. -e 's/^[SK][0-9]*//' -e 's/\.sh$//')
21
22 # To get the service to restart correctly on reboot, uncomment below (3 lines):
23 # ========================
24 # chkconfig: 3 99 99
25 # description: Eclipse Jetty webserver
26 # processname: jetty
27 # ========================
28
29 # Configuration files
30 #
31 # /etc/default/$NAME
32 # If it exists, this is read at the start of script. It may perform any
33 # sequence of shell commands, like setting relevant environment variables.
34 #
35 # $HOME/.$NAMErc (e.g. $HOME/.jettyrc)
36 # If it exists, this is read at the start of script. It may perform any
37 # sequence of shell commands, like setting relevant environment variables.
38 #
39 # /etc/$NAME.conf
40 # If found, and no configurations were given on the command line,
41 # the file will be used as this script's configuration.
42 # Each line in the file may contain:
43 # - A comment denoted by the pound (#) sign as first non-blank character.
44 # - The path to a regular file, which will be passed to jetty as a
45 # config.xml file.
46 # - The path to a directory. Each *.xml file in the directory will be
47 # passed to jetty as a config.xml file.
48 # - All other lines will be passed, as-is to the start.jar
49 #
50 # The files will be checked for existence before being passed to jetty.
51 #
52 # Configuration variables
53 #
54 # JAVA
55 # Command to invoke Java. If not set, java (from the PATH) will be used.
56 #
57 # JAVA_OPTIONS
58 # Extra options to pass to the JVM
59 #
60 # JETTY_HOME
61 # Where Jetty is installed. If not set, the script will try go
62 # guess it by looking at the invocation path for the script
63 # The java system property "jetty.home" will be
64 # set to this value for use by configure.xml files, f.e.:
65 #
66 # <Arg><Property name="jetty.home" default="."/>/webapps/jetty.war</Arg>
67 #
68 # JETTY_BASE
69 # Where your Jetty base directory is. If not set, then the currently
70 # directory is checked, otherwise the value from
71 # $JETTY_HOME will be used.
72 #
73 # JETTY_RUN
74 # Where the $NAME.pid file should be stored. It defaults to the
75 # first available of /var/run, /usr/var/run, JETTY_BASE and /tmp
76 # if not set.
77 #
78 # JETTY_PID
79 # The Jetty PID file, defaults to $JETTY_RUN/$NAME.pid
80 #
81 # JETTY_ARGS
82 # The default arguments to pass to jetty.
83 # For example
84 # JETTY_ARGS=jetty.http.port=8080 jetty.ssl.port=8443
85 #
86 # JETTY_USER
87 # if set, then used as a username to run the server as
88 #
89 # JETTY_SHELL
90 # If set, then used as the shell by su when starting the server. Will have
91 # no effect if start-stop-daemon exists. Useful when JETTY_USER does not
92 # have shell access, e.g. /bin/false
93 #
94 # JETTY_START_TIMEOUT
95 # Time spent waiting to see if startup was successful/failed. Defaults to 60 seconds
96 #
97
98 usagescip-shell shell shell-project 0.0.0 usage().()
99 {
100 echoscip-shell system . . echo. "Usage: ${0##*/} [-d] {start|stop|run|restart|check|supervise} [ CONFIGS ... ] "
101 exit 1
102 }
103
104 [scip-shell system . . `[`. $# -gt 0 ] || usagescip-shell shell shell-project 0.0.0 usage().
105
106
107 ##################################################
108 # Some utility functions
109 ##################################################
110 findDirectoryscip-shell shell shell-project 0.0.0 findDirectory().()
111 {
112 local L OP=$1
113 shift
114 for L in "$@"; do
115 [scip-shell system . . `[`. "$OP" "$L" ] || continue
116 printfscip-shell system . . printf. %s "$L"
117 break
118 done
119 }
120
121 # test if process specified in PID file is still running
122 runningscip-shell shell shell-project 0.0.0 running().()
123 {
124 local PIDFILE=$1
125 if [scip-shell system . . `[`. -r "$PIDFILE" ] ; then
126 local PID=$(tailscip-shell system . . tail. -1 "$PIDFILE")
127 if killscip-shell system . . kill. -0 "$PID" 2>/dev/nullscip-shell filesystem . . `/dev/null`. ; then
128 return 0
129 fi
130 fi
131 return 1
132 }
133
134 # Test state file (after timeout) for started state
135 startedscip-shell shell shell-project 0.0.0 started().()
136 {
137 local STATEFILE=$1
138 local PIDFILE=$2
139 local STARTTIMEOUT=$3
140
141 if (( DEBUG )) ; then
142 echoscip-shell system . . echo. "Looking for $STATEFILE"
143 echoscip-shell system . . echo. -n "State Parent Directory: "
144 lsscip-shell system . . ls. -lad $(dirnamescip-shell system . . dirname. $STATEFILE)
145 fi
146
147 # wait till timeout to see "STARTED" in state file, needs --module=state as argument
148 for ((T = 0; T < $STARTTIMEOUT; T++))
149 do
150 echo -n "."
151 sleep 1
152 if [ -r $STATEFILE ] ; then
153 STATENOW=$(tail -1 $STATEFILE)
154 (( DEBUG )) && echo "State (now): $STATENOW"
155 case "$STATENOW" in
156 STARTED*)
157 echo " started"
158 return 0;;
159 STOPPED*)
160 echo " stopped"
161 return 1;;
162 FAILED*)
163 echo " failed"
164 return 1;;
165 esac
166 else
167 (( DEBUG )) && echo "Unable to read State File: $STATEFILE"
168 fi
169 done
170 (( DEBUG )) && echoscip-shell system . . echo. "Timeout $STARTTIMEOUT expired waiting for start state from $STATEFILE"
171 echoscip-shell system . . echo. " timeout"
172 if runningscip-shell shell shell-project 0.0.0 running(). "$PIDFILE" ; then
173 echoscip-shell system . . echo. "INFO: Server process is running"
174 else
175 echoscip-shell system . . echo. "** ERROR: Server process is NOT running"
176 fi
177 return 1;
178 }
179
180 pidKillscip-shell shell shell-project 0.0.0 pidKill().()
181 {
182 local PIDFILE=$1
183 local TIMEOUT=$2
184
185 if [scip-shell system . . `[`. -r $PIDFILE ] ; then
186 local PID=$(tailscip-shell system . . tail. -1 "$PIDFILE")
187 if [scip-shell system . . `[`. -z "$PID" ] ; then
188 echoscip-shell system . . echo. "** ERROR: no pid found in $PIDFILE"
189 return 1
190 fi
191
192 # Try default kill first
193 if killscip-shell system . . kill. -0 "$PID" 2>/dev/nullscip-shell filesystem . . `/dev/null`. ; then
194 (( DEBUG )) && echoscip-shell system . . echo. "PID=$PID is running, sending kill"
195 killscip-shell system . . kill. "$PID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
196 else
197 rmscip-shell system . . rm. -f $PIDFILE 2> /dev/nullscip-shell filesystem . . `/dev/null`.
198 return 0
199 fi
200
201 # Perform harsh kill next
202 while killscip-shell system . . kill. -0 "$PID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
203 do
204 if (( TIMEOUT-- == 0 )) ; then
205 (( DEBUG )) && echoscip-shell system . . echo. "PID=$PID is running, sending kill signal=KILL (TIMEOUT=$TIMEOUT)"
206 killscip-shell system . . kill. -KILL "$PID" 2>/dev/nullscip-shell filesystem . . `/dev/null`.
207 fi
208 echoscip-shell system . . echo. -n "."
209 sleepscip-shell system . . sleep. 1
210 done
211 echoscip-shell system . . echo. "Killed $PID"
212 return 0
213 else
214 (( DEBUG )) && echoscip-shell system . . echo. "Unable to read PID File: $PIDFILE"
215 return 1
216 fi
217 }
218
219 testFileSystemPermissionsscip-shell shell shell-project 0.0.0 testFileSystemPermissions().()
220 {
221 # Don't test file system permissions if user is root
222 if [scip-shell system . . `[`. $UID -eq 0 ] ; then
223 (( DEBUG )) && echoscip-shell system . . echo. "Not testing file system permissions: uid is 0"
224 return 0
225 fi
226
227 # Don't test if JETTY_USER is specified
228 # as the Jetty process will switch to a different user id on startup
229 if [scip-shell system . . `[`. -n "$JETTY_USER" ] ; then
230 (( DEBUG )) && echoscip-shell system . . echo. "Not testing file system permissions: JETTY_USER=$JETTY_USER"
231 return 0
232 fi
233
234 # Don't test if setuid is specified
235 # as the Jetty process will switch to a different user id on startup
236 if exprscip-shell system . . expr. -- "${JETTY_ARGS[*]}" : '.*setuid.*' >/dev/nullscip-shell filesystem . . `/dev/null`.
237 then
238 (( DEBUG )) && echoscip-shell system . . echo. "Not testing file system permissions: setuid in use"
239 return 0
240 fi
241
242 # Test if PID can be written from this userid
243 if ! touchscip-shell system . . touch. "$JETTY_PID"
244 then
245 echoscip-shell system . . echo. "** ERROR: Unable to touch file: $JETTY_PID"
246 echoscip-shell system . . echo. " Correct issues preventing use of \$JETTY_PID and try again."
247 exit 1
248 fi
249
250 # Test if STATE can be written from this userid
251 if ! touchscip-shell system . . touch. "$JETTY_STATE"
252 then
253 echoscip-shell system . . echo. "** ERROR: Unable to touch file: $JETTY_STATE"
254 echoscip-shell system . . echo. " Correct issues preventing use of \$JETTY_STATE and try again."
255 exit 1
256 fi
257 }
258
259 readConfigscip-shell shell shell-project 0.0.0 readConfig().()
260 {
261 (( DEBUG )) && echoscip-shell system . . echo. "Reading $1.."
262 source "$1"
263 }
264
265 dumpEnvscip-shell shell shell-project 0.0.0 dumpEnv().()
266 {
267 echoscip-shell system . . echo. "JAVA = $JAVA"
268 echoscip-shell system . . echo. "JAVA_OPTIONS = ${JAVA_OPTIONS[*]}"
269 echoscip-shell system . . echo. "JETTY_HOME = $JETTY_HOME"
270 echoscip-shell system . . echo. "JETTY_BASE = $JETTY_BASE"
271 echoscip-shell system . . echo. "START_D = $START_D"
272 echoscip-shell system . . echo. "START_INI = $START_INI"
273 echoscip-shell system . . echo. "JETTY_START = $JETTY_START"
274 echoscip-shell system . . echo. "JETTY_CONF = $JETTY_CONF"
275 echoscip-shell system . . echo. "JETTY_ARGS = ${JETTY_ARGS[*]}"
276 echoscip-shell system . . echo. "JETTY_RUN = $JETTY_RUN"
277 echoscip-shell system . . echo. "JETTY_PID = $JETTY_PID"
278 echoscip-shell system . . echo. "JETTY_START_LOG = $JETTY_START_LOG"
279 echoscip-shell system . . echo. "JETTY_STATE = $JETTY_STATE"
280 echoscip-shell system . . echo. "JETTY_START_TIMEOUT = $JETTY_START_TIMEOUT"
281 echoscip-shell system . . echo. "JETTY_SYS_PROPS = $JETTY_SYS_PROPS"
282 echoscip-shell system . . echo. "RUN_ARGS = ${RUN_ARGS[*]}"
283 echoscip-shell system . . echo. "ID = $(idscip-shell system . . id.)"
284 echoscip-shell system . . echo. "JETTY_USER = $JETTY_USER"
285 echoscip-shell system . . echo. "USE_START_STOP_DAEMON = $USE_START_STOP_DAEMON"
286 echoscip-shell system . . echo. "START_STOP_DAEMON = $START_STOP_DAEMON_AVAILABLE"
287 }
288
289
290 ##################################################
291 # Get the action & configs
292 ##################################################
293 CONFIGS=()
294 NO_START=0
295 DEBUG=0
296 USE_START_STOP_DAEMON=1
297
298 while [[ $1 = -* ]]; do
299 case $1 in
300 -d) DEBUG=1 ;;
301 esac
302 shift
303 done
304 ACTION=$1
305 shift
306
307 ##################################################
308 # Read any configuration files
309 ##################################################
310 ETC=/etcscip-shell filesystem . . `/etc`.
311 if [scip-shell system . . `[`. $UID != 0 ]
312 then
313 ETC=$HOME/etc
314 fi
315
316 for CONFIG in {/etc,~/etc}/default/${NAME}{,9} $HOME/.${NAME}rc; do
317 if [scip-shell system . . `[`. -f "$CONFIG" ] ; then
318 readConfigscip-shell shell shell-project 0.0.0 readConfig(). "$CONFIG"
319 fi
320 done
321
322
323 ##################################################
324 # Set tmp if not already set.
325 ##################################################
326 TMPDIR=${TMPDIR:-/tmp}
327
328 ##################################################
329 # Jetty's hallmark
330 ##################################################
331 JETTY_INSTALL_TRACE_FILE="start.jar"
332
333
334 ##################################################
335 # Try to determine JETTY_HOME if not set
336 ##################################################
337 if [scip-shell system . . `[`. -z "$JETTY_HOME" ]
338 then
339 JETTY_SH=$0
340 case "$JETTY_SH" in
341 /*) JETTY_HOME=${JETTY_SH%/*/*} ;;
342 ./*/*) JETTY_HOME=${JETTY_SH%/*/*} ;;
343 ./*) JETTY_HOME=.. ;;
344 */*/*) JETTY_HOME=./${JETTY_SH%/*/*} ;;
345 */*) JETTY_HOME=. ;;
346 *) JETTY_HOME=.. ;;
347 esac
348
349 if [scip-shell system . . `[`. ! -f "$JETTY_HOME/$JETTY_INSTALL_TRACE_FILE" ]
350 then
351 JETTY_HOME=
352 fi
353 fi
354
355 ##################################################
356 # No JETTY_HOME yet? We're out of luck!
357 ##################################################
358 if [scip-shell system . . `[`. -z "$JETTY_HOME" ]; then
359 echoscip-shell system . . echo. "** ERROR: JETTY_HOME not set, you need to set it or install in a standard location"
360 exit 1
361 fi
362
363 RUN_DIR=$(pwdscip-shell system . . pwd.)
364 cd "$JETTY_HOME"
365 JETTY_HOME=$(pwdscip-shell system . . pwd.)
366
367 ##################################################
368 # Set JETTY_BASE
369 ##################################################
370 export JETTY_BASE
371 if [scip-shell system . . `[`. -z "$JETTY_BASE" ]; then
372 if [scip-shell system . . `[`. -d "$RUN_DIR/start.d" -o -f "$RUN_DIR/start.ini" ]; then
373 JETTY_BASE=$RUN_DIR
374 else
375 JETTY_BASE=$JETTY_HOME
376 fi
377 fi
378 cd "$JETTY_BASE"
379 JETTY_BASE=$(pwdscip-shell system . . pwd.)
380
381 #####################################################
382 # Check that jetty is where we think it is
383 #####################################################
384 if [scip-shell system . . `[`. ! -r "$JETTY_HOME/$JETTY_INSTALL_TRACE_FILE" ]
385 then
386 echoscip-shell system . . echo. "** ERROR: Oops! Jetty doesn't appear to be installed in $JETTY_HOME"
387 echoscip-shell system . . echo. "** ERROR: $JETTY_HOME/$JETTY_INSTALL_TRACE_FILE is not readable!"
388 exit 1
389 fi
390
391 ##################################################
392 # Try to find this script's configuration file,
393 # but only if no configurations were given on the
394 # command line.
395 ##################################################
396 if [scip-shell system . . `[`. -z "$JETTY_CONF" ]
397 then
398 if [scip-shell system . . `[`. -f $ETC/${NAME}.conf ]
399 then
400 JETTY_CONF=$ETC/${NAME}.conf
401 elif [scip-shell system . . `[`. -f "$JETTY_BASE/etc/jetty.conf" ]
402 then
403 JETTY_CONF=$JETTY_BASE/etc/jetty.conf
404 elif [scip-shell system . . `[`. -f "$JETTY_HOME/etc/jetty.conf" ]
405 then
406 JETTY_CONF=$JETTY_HOME/etc/jetty.conf
407 fi
408 fi
409
410 #####################################################
411 # Find a location for the pid file
412 #####################################################
413 if [scip-shell system . . `[`. -z "$JETTY_RUN" ]
414 then
415 JETTY_RUN=$(findDirectoryscip-shell shell shell-project 0.0.0 findDirectory(). -w /var/runscip-shell filesystem . . `/var/run`. /usr/var/runscip-shell filesystem . . `/usr/var/run`. $JETTY_BASE /tmpscip-shell filesystem . . `/tmp`.)/jetty
416 fi
417
418 if [scip-shell system . . `[`. ! -d "$JETTY_RUN" ] ; then
419 if ! mkdirscip-shell system . . mkdir. $JETTY_RUN
420 then
421 echoscip-shell system . . echo. "** ERROR: Unable to create directory: $JETTY_RUN"
422 echoscip-shell system . . echo. " Correct issues preventing the creation of \$JETTY_RUN and try again."
423 exit 1
424 fi
425 fi
426
427 #####################################################
428 # define start log location
429 #####################################################
430 if [scip-shell system . . `[`. -z "$JETTY_START_LOG" ]
431 then
432 JETTY_START_LOG="$JETTY_RUN/$NAME-start.log"
433 fi
434
435 #####################################################
436 # Find a pid and state file
437 #####################################################
438 if [scip-shell system . . `[`. -z "$JETTY_PID" ]
439 then
440 JETTY_PID="$JETTY_RUN/${NAME}.pid"
441 fi
442
443 if [scip-shell system . . `[`. -z "$JETTY_STATE" ]
444 then
445 JETTY_STATE=$JETTY_BASE/${NAME}.state
446 fi
447
448 case "`unamescip-shell system . . uname.`" in
449 CYGWIN*) JETTY_STATE="`cygpath -w $JETTY_STATE`";;
450 esac
451
452 JETTY_ARGS=(${JETTY_ARGS[*]} "jetty.state=$JETTY_STATE" "jetty.pid=$JETTY_PID")
453
454 ##################################################
455 # Get the list of config.xml files from jetty.conf
456 ##################################################
457 if [scip-shell system . . `[`. -f "$JETTY_CONF" ] && [scip-shell system . . `[`. -r "$JETTY_CONF" ]
458 then
459 (( DEBUG )) && echoscip-shell system . . echo. "$JETTY_CONF: (begin read) JETTY_ARGS.length=${#JETTY_ARGS[@]}"
460 while read -r CONF
461 do
462 if exprscip-shell system . . expr. -- "$CONF" : '#' >/dev/nullscip-shell filesystem . . `/dev/null`. ; then
463 continue
464 fi
465
466 if [scip-shell system . . `[`. -d "$CONF" ]
467 then
468 # assume it's a directory with configure.xml files
469 # for example: /etc/jetty.d/
470 # sort the files before adding them to the list of JETTY_ARGS
471 for XMLFILE in "$CONF/"*.xml
472 do
473 if [scip-shell system . . `[`. -r "$XMLFILE" ] && [scip-shell system . . `[`. -f "$XMLFILE" ]
474 then
475 JETTY_ARGS[${#JETTY_ARGS[@]}]=$XMLFILE
476 else
477 echoscip-shell system . . echo. "** WARNING: Cannot read '$XMLFILE' specified in '$JETTY_CONF'"
478 fi
479 done
480 else
481 # assume it's a command line parameter (let start.jar deal with its validity)
482 JETTY_ARGS[${#JETTY_ARGS[@]}]=$CONF
483 fi
484 done < "$JETTY_CONF"
485 (( DEBUG )) && echoscip-shell system . . echo. "$JETTY_CONF: (finished read) JETTY_ARGS.length=${#JETTY_ARGS[@]}"
486 fi
487
488 ##################################################
489 # Setup JAVA if unset
490 ##################################################
491 if [scip-shell system . . `[`. -z "$JAVA" ]
492 then
493 JAVA=$(whichscip-shell system . . which. java)
494 fi
495
496 if [scip-shell system . . `[`. -z "$JAVA" ]
497 then
498 echoscip-shell system . . echo. "Cannot find a Java JDK. Please set either set JAVA or put java (>=1.5) in your PATH." >&2
499 exit 1
500 fi
501
502 #####################################################
503 # See if Deprecated JETTY_LOGS is defined
504 #####################################################
505 if [scip-shell system . . `[`. "$JETTY_LOGS" ]
506 then
507 echoscip-shell system . . echo. "** WARNING: JETTY_LOGS is Deprecated. Please configure logging within the jetty base." >&2
508 fi
509
510 #####################################################
511 # Set STARTED timeout
512 #####################################################
513 if [scip-shell system . . `[`. -z "$JETTY_START_TIMEOUT" ]
514 then
515 JETTY_START_TIMEOUT=60
516 fi
517
518 #####################################################
519 # Are we running on Windows? Could be, with Cygwin/NT.
520 #####################################################
521 case "`unamescip-shell system . . uname.`" in
522 CYGWIN*) PATH_SEPARATOR=";";;
523 *) PATH_SEPARATOR=":";;
524 esac
525
526
527 #####################################################
528 # Add jetty properties to Java VM options.
529 #####################################################
530
531 case "`unamescip-shell system . . uname.`" in
532 CYGWIN*)
533 JETTY_HOME="`cygpath -w $JETTY_HOME`"
534 JETTY_BASE="`cygpath -w $JETTY_BASE`"
535 TMPDIR="`cygpath -w $TMPDIR`"
536 ;;
537 esac
538
539 #####################################################
540 # This is how the Jetty server will be started
541 #####################################################
542
543 JETTY_START=$JETTY_HOME/start.jar
544 START_INI=$JETTY_BASE/start.ini
545 START_D=$JETTY_BASE/start.d
546 if [scip-shell system . . `[`. ! -f "$START_INI" -a ! -d "$START_D" ]
547 then
548 echoscip-shell system . . echo. "Cannot find a start.ini file or a start.d directory in your JETTY_BASE directory: $JETTY_BASE" >&2
549 exit 1
550 fi
551
552 case "`unamescip-shell system . . uname.`" in
553 CYGWIN*) JETTY_START="`cygpath -w $JETTY_START`";;
554 esac
555
556 # Determine if we can use start-stop-daemon or not
557 START_STOP_DAEMON_AVAILABLE=0
558
559 if (( USE_START_STOP_DAEMON ))
560 then
561 # only if root user is executing jetty.sh, and the start-stop-daemon exists
562 if [scip-shell system . . `[`. $UID -eq 0 ] && type start-stop-daemon > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
563 then
564 START_STOP_DAEMON_AVAILABLE=1
565 else
566 USE_START_STOP_DAEMON=0
567 fi
568 fi
569
570 # Collect the dry-run (of opts,path,main,args,envs) from the jetty.base configuration
571 JETTY_DRY_RUN=$(echoscip-shell system . . echo. "${JETTY_ARGS[*]} ${JAVA_OPTIONS[*]}" | xargsscip-shell system . . xargs. "$JAVA" -jar "$JETTY_START" --dry-run=opts,path,main,args,envs)
572 RUN_ARGS=($JETTY_SYS_PROPS ${JETTY_DRY_RUN[@]})
573
574 if (( DEBUG ))
575 then
576 if exprscip-shell system . . expr. -- "${RUN_ARGS[*]}" : '.*/etc/console-capture.xml.*' > /dev/nullscip-shell filesystem . . `/dev/null`.
577 then
578 echoscip-shell system . . echo. "WARNING: Disable console-capture module for best DEBUG results"
579 fi
580 echoscip-shell system . . echo. "IDs are $(idscip-shell system . . id.)"
581 dumpEnvscip-shell shell shell-project 0.0.0 dumpEnv().
582 fi
583
584 ##################################################
585 # Do the action
586 ##################################################
587 case "$ACTION" in
588 start)
589 if (( NO_START )); then
590 echoscip-shell system . . echo. "Not starting ${NAME} - NO_START=1";
591 exit
592 fi
593
594 testFileSystemPermissionsscip-shell shell shell-project 0.0.0 testFileSystemPermissions().
595
596 if runningscip-shell shell shell-project 0.0.0 running(). $JETTY_PID
597 then
598 echoscip-shell system . . echo. "Already Running $(catscip-shell system . . cat. $JETTY_PID)!"
599 exit 1
600 fi
601
602 # remove any lingering state file
603 if [scip-shell system . . `[`. -f $JETTY_STATE ]
604 then
605 rmscip-shell system . . rm. $JETTY_STATE
606 fi
607
608 echoscip-shell system . . echo. -n "Starting Jetty: "
609
610 # Startup from a service file
611 if (( USE_START_STOP_DAEMON ))
612 then
613 unset CH_USER
614 if [scip-shell system . . `[`. -n "$JETTY_USER" ]
615 then
616 CH_USER="--chuid $JETTY_USER"
617 fi
618
619 # use of --pidfile /dev/null disables internal pidfile
620 # management of the start-stop-daemon (see man page)
621 echoscip-shell system . . echo. ${RUN_ARGS[@]} | xargsscip-shell system . . xargs. start-stop-daemon \
622 --start $CH_USER \
623 --pidfile /dev/nullscip-shell filesystem . . `/dev/null`. \
624 --chdir "$JETTY_BASE" \
625 --background \
626 --output "${JETTY_RUN}/start-stop.log" \
627 --startas "$JAVA" \
628 --
629 (( DEBUG )) && echoscip-shell system . . echo. "Starting: start-stop-daemon"
630 else
631 # Startup if switching users (not as a service, or from root)
632 if [scip-shell system . . `[`. -n "$JETTY_USER" ] && [scip-shell system . . `[`. `whoamiscip-shell system . . whoami.` != "$JETTY_USER" ]
633 then
634 unset SU_SHELL
635 if [scip-shell system . . `[`. "$JETTY_SHELL" ]
636 then
637 SU_SHELL="-s $JETTY_SHELL"
638 fi
639
640 chownscip-shell system . . chown. "$JETTY_USER" "$JETTY_PID"
641 suscip-shell system . . su. - "$JETTY_USER" $SU_SHELL -c "
642 cd \"$JETTY_BASE\"
643 echo ${RUN_ARGS[*]} | xargs ${JAVA} > /dev/null &
644 PID=\$!
645 disown \$PID"
646 (( DEBUG )) && echoscip-shell system . . echo. "Starting: su shell (w/user $JETTY_USER) on PID $PID"
647 else
648 # Startup if not switching users
649 echoscip-shell system . . echo. ${RUN_ARGS[*]} | xargsscip-shell system . . xargs. ${JAVA} > /dev/nullscip-shell filesystem . . `/dev/null`. &
650 PID=$!
651 disown $PID
652 (( DEBUG )) && echoscip-shell system . . echo. "Starting: java command on PID $PID"
653 fi
654 fi
655
656 if exprscip-shell system . . expr. -- "${JETTY_ARGS[*]}" : '.*jetty\.state=.*' >/dev/nullscip-shell filesystem . . `/dev/null`.
657 then
658 if startedscip-shell shell shell-project 0.0.0 started(). "$JETTY_STATE" "$JETTY_PID" "$JETTY_START_TIMEOUT"
659 then
660 echoscip-shell system . . echo. "OK `datescip-shell system . . date.`"
661 else
662 echoscip-shell system . . echo. "FAILED `datescip-shell system . . date.`"
663 pidKillscip-shell shell shell-project 0.0.0 pidKill(). $JETTY_PID 30
664 exit 1
665 fi
666 else
667 echoscip-shell system . . echo. "ok `datescip-shell system . . date.`"
668 fi
669
670 ;;
671
672 stop)
673 echoscip-shell system . . echo. -n "Stopping Jetty: "
674 if [scip-shell system . . `[`. ! -r "$JETTY_PID" ] ; then
675 echoscip-shell system . . echo. "** ERROR: no pid found at $JETTY_PID"
676 exit 1
677 fi
678
679 PID=$(tailscip-shell system . . tail. -1 "$JETTY_PID")
680 if [scip-shell system . . `[`. -z "$PID" ] ; then
681 echoscip-shell system . . echo. "** ERROR: no pid found in $JETTY_PID"
682 exit 1
683 fi
684
685 # Stopping service started with start-stop-daemon
686 if (( USE_START_STOP_DAEMON )) ; then
687 (( DEBUG )) && echoscip-shell system . . echo. "Issuing HUP to $PID"
688 start-stop-daemonscip-shell system . . start-stop-daemon. --stop \
689 --pid "$PID" \
690 --chdir "$JETTY_BASE" \
691 --startas "$JAVA" \
692 --signal HUP
693
694 TIMEOUT=30
695 while runningscip-shell shell shell-project 0.0.0 running(). "$JETTY_PID"; do
696 (( DEBUG )) && echoscip-shell system . . echo. "Issuing KILL to $PID"
697 if (( TIMEOUT-- == 0 )); then
698 start-stop-daemonscip-shell system . . start-stop-daemon. --stop \
699 --pid "$PID" \
700 --chdir "$JETTY_BASE" \
701 --startas "$JAVA" \
702 --signal KILL
703 fi
704
705 sleepscip-shell system . . sleep. 1
706 done
707 else
708 # Stopping from non-service start
709 pidKillscip-shell shell shell-project 0.0.0 pidKill(). "$JETTY_PID" 30
710 fi
711
712 rmscip-shell system . . rm. -f "$JETTY_PID"
713 rmscip-shell system . . rm. -f "$JETTY_STATE"
714 echoscip-shell system . . echo. OK
715
716 ;;
717
718 restart)
719 JETTY_SH=$0
720 echoscip-shell system . . echo. "restart" >> "$JETTY_STATE"
721 if [scip-shell system . . `[`. ! -f $JETTY_SH ]; then
722 if [scip-shell system . . `[`. ! -f $JETTY_HOME/bin/jetty.sh ]; then
723 echoscip-shell system . . echo. "$JETTY_HOME/bin/jetty.sh does not exist."
724 exit 1
725 fi
726 JETTY_SH=$JETTY_HOME/bin/jetty.sh
727 fi
728
729 "$JETTY_SH" stop "$@"
730 "$JETTY_SH" start "$@"
731
732 ;;
733
734 supervise)
735 #
736 # Under control of daemontools supervise monitor which
737 # handles restarts and shutdowns via the svc program.
738 #
739 echoscip-shell system . . echo. ${RUN_ARGS[*]} | xargsscip-shell system . . xargs. ${JAVA} > /dev/nullscip-shell filesystem . . `/dev/null`. &
740
741 ;;
742
743 run|demo)
744 echoscip-shell system . . echo. "Running Jetty: "
745
746 if runningscip-shell shell shell-project 0.0.0 running(). "$JETTY_PID"
747 then
748 echoscip-shell system . . echo. Already Running $(catscip-shell system . . cat. "$JETTY_PID")!
749 exit 1
750 fi
751
752 echoscip-shell system . . echo. ${RUN_ARGS[*]} | xargsscip-shell system . . xargs. ${JAVA} > /dev/nullscip-shell filesystem . . `/dev/null`. &
753 ;;
754
755 check|status)
756 if runningscip-shell shell shell-project 0.0.0 running(). "$JETTY_PID"
757 then
758 echoscip-shell system . . echo. "Jetty running pid=$(< "$JETTY_PID")"
759 else
760 echoscip-shell system . . echo. "Jetty NOT running"
761 fi
762 echoscip-shell system . . echo.
763 dumpEnvscip-shell shell shell-project 0.0.0 dumpEnv().
764 echoscip-shell system . . echo.
765
766 if runningscip-shell shell shell-project 0.0.0 running(). "$JETTY_PID"
767 then
768 exit 0
769 fi
770 exit 1
771
772 ;;
773
774 *)
775 usagescip-shell shell shell-project 0.0.0 usage().
776
777 ;;
778 esac
779
780 exit 0