Skip to content

Commit 7011944

Browse files
committed
Add workaround for race condition in start-stop-daemon
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
1 parent fc5e3d6 commit 7011944

File tree

1 file changed

+15
-0
lines changed
  • spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools

1 file changed

+15
-0
lines changed

spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ isRunning() {
8080
ps -p $1 &> /dev/null
8181
}
8282

83+
await_file() {
84+
end=`date +%s`
85+
let "end+=10"
86+
while [ ! -f $1 ]
87+
do
88+
now=`date +%s`
89+
echo $now
90+
if [[ $now -ge $end ]]; then
91+
break
92+
fi
93+
sleep 1
94+
done
95+
}
96+
8397
# Determine the script mode
8498
action="run"
8599
if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then
@@ -142,6 +156,7 @@ do_start() {
142156
-Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS \
143157
-jar $jarfile $RUN_ARGS "$@" \
144158
> $log_file 2>&1
159+
await_file $pid_file
145160
else
146161
su -s /bin/sh -c "$command &> \"$log_file\" & echo \$!" $run_user > "$pid_file"
147162
fi

0 commit comments

Comments
 (0)