Wait for Xvfb to startup

This commit is contained in:
guenhter 2018-09-14 08:56:20 +02:00
parent e283569897
commit 8e1071aad0
2 changed files with 20 additions and 7 deletions

View file

@ -1,4 +1,4 @@
FROM node:6-stretch
FROM node:6.15.1-stretch
MAINTAINER Petr Sloup <petr.sloup@klokantech.com>
ENV NODE_ENV="production"
@ -21,6 +21,7 @@ RUN apt-get -qq update \
libprotobuf-dev \
libxxf86vm-dev \
xvfb \
x11-utils \
&& apt-get clean
RUN mkdir -p /usr/src/app

24
run.sh
View file

@ -5,17 +5,29 @@ _term() {
kill -TERM "$child" 2>/dev/null
}
trap _term TERM
trap _term SIGTERM
trap _term SIGINT
xvfbMaxStartWaitTime=5
displayNumber=99
screenNumber=0
# Delete files if they were not cleaned by last run
rm -rf /tmp/.X11-unix /tmp/.X99-lock
rm -rf /tmp/.X11-unix /tmp/.X${displayNumber}-lock ~/xvfb.pid
start-stop-daemon --start --pidfile ~/xvfb.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 1024x768x24 -ac +extension GLX +render -noreset
echo "Waiting 3 seconds for xvfb to start..."
sleep 3
echo "Starting Xvfb on display ${displayNumber}"
start-stop-daemon --start --pidfile ~/xvfb.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :${displayNumber} -screen ${screenNumber} 1024x768x24 -ac +extension GLX +render -noreset
export DISPLAY=:99.0
# Wait to be able to connect to the port. This will exit if it cannot in 15 minutes.
timeout ${xvfbMaxStartWaitTime} bash -c "while ! xdpyinfo -display :${displayNumber} >/dev/null; do sleep 0.5; done"
if [ $? -ne 0 ]; then
echo "Could not connect to display ${displayNumber} in ${xvfbMaxStartWaitTime} seconds time."
exit 1
fi
export DISPLAY=:${displayNumber}.${screenNumber}
echo
cd /data
node /usr/src/app/ -p 80 "$@" &
child=$!