Trying to modify run.sh so it waits for the Xvfb server to start accepting connections.

This commit is contained in:
polar 2017-09-20 09:57:11 -04:00
parent fac50c9bc6
commit 6f54d9228a

21
run.sh
View file

@ -1,7 +1,7 @@
#!/bin/bash
start-stop-daemon --start --pidfile ~/xvfb.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1024x768x24 -ac +extension GLX +render -noreset
let p=80
# Find an open port
let p=99
while [ ${p} -lt 3000 ]
do
if nc -z localhost ${p}; then
@ -11,15 +11,20 @@ while [ ${p} -lt 3000 ]
break
fi
done
echo The port is ${port}
if ${port}; then
echo The display port will be ${port}
start-stop-daemon --start --pidfile ~/xvfb.pid --make-pidfile --background \
--exec /usr/bin/Xvfb -- :${port} -screen 0 1024x768x24 \
-ac +extension GLX +render -noreset
# Wait to be able to connect to the port. This will exit if it cannot in 15 minutes.
timeout 15 bash -c "until echo > /dev/tcp/localhost/${port}; do sleep 0.5; done"
export DISPLAY=:${port}.0
cd /data
node /usr/src/app/ -p 80 "$@"
else
echo "Could get a display port ${port}."
exit 1
fi
export DISPLAY=:${port}.0
cd /data
node /usr/src/app/ -p 80 "$@"