From 70119449ced768ef32c5a60930aafe3c29865688 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 1 Dec 2015 11:47:06 +0000 Subject: [PATCH] Add workaround for race condition in start-stop-daemon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s a race condition in start-stop-daemon when --make-pidfile and --background are used together [1]. This race condition can lead to the command returning before the PID file has been created. The missing PID file then causes the launch script to incorrectly report that the service failed to start. This commit updates the launch script to wait for up to 10 seconds for the PID file to be created when start-stop-daemon is used to launch the app. Closes gh-4524 [1] https://bugs.launchpad.net/ubuntu/+source/dpkg/+bug/1036899 --- .../boot/loader/tools/launch.script | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script index d0edff54af..ab1338910e 100755 --- a/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script +++ b/spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script @@ -80,6 +80,20 @@ isRunning() { ps -p $1 &> /dev/null } +await_file() { + end=`date +%s` + let "end+=10" + while [ ! -f $1 ] + do + now=`date +%s` + echo $now + if [[ $now -ge $end ]]; then + break + fi + sleep 1 + done +} + # Determine the script mode action="run" if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then @@ -142,6 +156,7 @@ do_start() { -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS \ -jar $jarfile $RUN_ARGS "$@" \ > $log_file 2>&1 + await_file $pid_file else su -s /bin/sh -c "$command &> \"$log_file\" & echo \$!" $run_user > "$pid_file" fi