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
This commit is contained in:
Andy Wilkinson 2015-12-01 11:47:06 +00:00
parent fc5e3d6441
commit 70119449ce
1 changed files with 15 additions and 0 deletions

View File

@ -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