@@ -216,6 +216,46 @@ pidKill()
216
216
fi
217
217
}
218
218
219
+ testFileSystemPermissions ()
220
+ {
221
+ # Don't test file system permissions if user is root
222
+ if [ $UID -eq 0 ] ; then
223
+ (( DEBUG )) && 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 [ -n " $JETTY_USER " ] ; then
230
+ (( DEBUG )) && 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 expr " ${JETTY_ARGS[*]} " : ' .*setuid.*' > /dev/null
237
+ then
238
+ (( DEBUG )) && 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 ! touch " $JETTY_PID "
244
+ then
245
+ echo " ** ERROR: Unable to touch file: $JETTY_PID "
246
+ 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 ! touch " $JETTY_STATE "
252
+ then
253
+ echo " ** ERROR: Unable to touch file: $JETTY_STATE "
254
+ echo " Correct issues preventing use of \$ JETTY_STATE and try again."
255
+ exit 1
256
+ fi
257
+ }
258
+
219
259
readConfig ()
220
260
{
221
261
(( DEBUG )) && echo " Reading $1 .."
@@ -240,6 +280,10 @@ dumpEnv()
240
280
echo " JETTY_START_TIMEOUT = $JETTY_START_TIMEOUT "
241
281
echo " JETTY_SYS_PROPS = $JETTY_SYS_PROPS "
242
282
echo " RUN_ARGS = ${RUN_ARGS[*]} "
283
+ echo " ID = $( id) "
284
+ echo " JETTY_USER = $JETTY_USER "
285
+ echo " USE_START_STOP_DAEMON = $USE_START_STOP_DAEMON "
286
+ echo " START_STOP_DAEMON = $START_STOP_DAEMON_AVAILABLE "
243
287
}
244
288
245
289
@@ -249,6 +293,7 @@ dumpEnv()
249
293
CONFIGS=()
250
294
NO_START=0
251
295
DEBUG=0
296
+ USE_START_STOP_DAEMON=1
252
297
253
298
while [[ $1 = -* ]]; do
254
299
case $1 in
@@ -404,14 +449,14 @@ case "`uname`" in
404
449
CYGWIN* ) JETTY_STATE=" ` cygpath -w $JETTY_STATE ` " ;;
405
450
esac
406
451
407
-
408
452
JETTY_ARGS=(${JETTY_ARGS[*]} " jetty.state=$JETTY_STATE " " jetty.pid=$JETTY_PID " )
409
453
410
454
# #################################################
411
455
# Get the list of config.xml files from jetty.conf
412
456
# #################################################
413
457
if [ -f " $JETTY_CONF " ] && [ -r " $JETTY_CONF " ]
414
458
then
459
+ (( DEBUG )) && echo " $JETTY_CONF : (begin read) JETTY_ARGS.length=${# JETTY_ARGS[@]} "
415
460
while read -r CONF
416
461
do
417
462
if expr " $CONF " : ' #' > /dev/null ; then
@@ -427,16 +472,17 @@ then
427
472
do
428
473
if [ -r " $XMLFILE " ] && [ -f " $XMLFILE " ]
429
474
then
430
- JETTY_ARGS=( ${ JETTY_ARGS[*]} " $XMLFILE " )
475
+ JETTY_ARGS[ ${ # JETTY_ARGS[@]} ]= $XMLFILE
431
476
else
432
477
echo " ** WARNING: Cannot read '$XMLFILE ' specified in '$JETTY_CONF '"
433
478
fi
434
479
done
435
480
else
436
481
# assume it's a command line parameter (let start.jar deal with its validity)
437
- JETTY_ARGS=( ${ JETTY_ARGS[*]} " $CONF " )
482
+ JETTY_ARGS[ ${ # JETTY_ARGS[@]} ]= $CONF
438
483
fi
439
484
done < " $JETTY_CONF "
485
+ (( DEBUG )) && echo " $JETTY_CONF : (finished read) JETTY_ARGS.length=${# JETTY_ARGS[@]} "
440
486
fi
441
487
442
488
# #################################################
@@ -507,8 +553,22 @@ case "`uname`" in
507
553
CYGWIN* ) JETTY_START=" ` cygpath -w $JETTY_START ` " ;;
508
554
esac
509
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 [ $UID -eq 0 ] && type start-stop-daemon > /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
+
510
570
# Collect the dry-run (of opts,path,main,args) from the jetty.base configuration
511
- JETTY_DRY_RUN=$( " $ JAVA" -jar " $JETTY_START " --dry-run=opts,path,main,args ${JETTY_ARGS[*]} ${JAVA_OPTIONS[*]} )
571
+ JETTY_DRY_RUN=$( echo " ${JETTY_ARGS[*]} ${JAVA_OPTIONS[*]} " | xargs " $ JAVA" -jar " $JETTY_START " --dry-run=opts,path,main,args)
512
572
RUN_ARGS=($JETTY_SYS_PROPS ${JETTY_DRY_RUN[@]} )
513
573
514
574
if (( DEBUG ))
@@ -531,38 +591,27 @@ case "$ACTION" in
531
591
exit
532
592
fi
533
593
534
- if ! touch " $JETTY_PID "
535
- then
536
- echo " ** ERROR: Unable to touch file: $JETTY_PID "
537
- echo " Correct issues preventing use of \$ JETTY_PID and try again."
538
- exit 1
539
- fi
540
-
541
- if ! touch " $JETTY_STATE "
542
- then
543
- echo " ** ERROR: Unable to touch file: $JETTY_STATE "
544
- echo " Correct issues preventing use of \$ JETTY_STATE and try again."
545
- exit 1
546
- fi
594
+ testFileSystemPermissions
547
595
548
596
echo -n " Starting Jetty: "
549
597
550
598
# Startup from a service file
551
- if [ $UID -eq 0 ] && type start-stop-daemon > /dev/null 2>&1
599
+ if (( USE_START_STOP_DAEMON ))
552
600
then
553
601
unset CH_USER
554
602
if [ -n " $JETTY_USER " ]
555
603
then
556
604
CH_USER=" --chuid $JETTY_USER "
557
605
fi
558
606
559
- echo ${RUN_ARGS[@]} --start-log-file=" $JETTY_START_LOG " | xargs start-stop-daemon \
607
+ # use of --pidfile /dev/null disables internal pidfile
608
+ # management of the start-stop-daemon (see man page)
609
+ echo ${RUN_ARGS[@]} | xargs start-stop-daemon \
560
610
--start $CH_USER \
561
- --pidfile " $JETTY_PID " \
611
+ --pidfile /dev/null \
562
612
--chdir " $JETTY_BASE " \
563
613
--background \
564
- --output " ${JETTY_RUN} /start-stop.log"
565
- --make-pidfile \
614
+ --output " ${JETTY_RUN} /start-stop.log" \
566
615
--startas " $JAVA " \
567
616
--
568
617
(( DEBUG )) && echo " Starting: start-stop-daemon"
@@ -618,25 +667,41 @@ case "$ACTION" in
618
667
619
668
stop)
620
669
echo -n " Stopping Jetty: "
621
- # Stop from a service file
622
- if [ $UID -eq 0 ] && type start-stop-daemon > /dev/null 2>&1 ; then
623
- start-stop-daemon -K -p" $JETTY_PID " -d" $JETTY_HOME " -a " $JAVA " -s HUP
670
+ if [ ! -r " $JETTY_PID " ] ; then
671
+ echo " ** ERROR: no pid found at $JETTY_PID "
672
+ exit 1
673
+ fi
674
+
675
+ PID=$( tail -1 " $JETTY_PID " )
676
+ if [ -z " $PID " ] ; then
677
+ echo " ** ERROR: no pid found in $JETTY_PID "
678
+ exit 1
679
+ fi
680
+
681
+ # Stopping service started with start-stop-daemon
682
+ if (( USE_START_STOP_DAEMON )) ; then
683
+ (( DEBUG )) && echo " Issuing HUP to $PID "
684
+ start-stop-daemon --stop \
685
+ --pid " $PID " \
686
+ --chdir " $JETTY_BASE " \
687
+ --startas " $JAVA " \
688
+ --signal HUP
624
689
625
690
TIMEOUT=30
626
691
while running " $JETTY_PID " ; do
692
+ (( DEBUG )) && echo " Issuing KILL to $PID "
627
693
if (( TIMEOUT-- == 0 )) ; then
628
- start-stop-daemon -K -p" $JETTY_PID " -d" $JETTY_HOME " -a " $JAVA " -s KILL
694
+ start-stop-daemon --stop \
695
+ --pid " $PID " \
696
+ --chdir " $JETTY_BASE " \
697
+ --startas " $JAVA " \
698
+ --signal KILL
629
699
fi
630
700
631
701
sleep 1
632
702
done
633
703
else
634
- # Stop from a non-service path
635
- if [ ! -r " $JETTY_PID " ] ; then
636
- echo " ** ERROR: no pid found at $JETTY_PID "
637
- exit 1
638
- fi
639
-
704
+ # Stopping from non-service start
640
705
pidKill " $JETTY_PID " 30
641
706
fi
642
707
0 commit comments