Skip to content

Commit

Permalink
Wait for Xvfb to startup
Browse files Browse the repository at this point in the history
  • Loading branch information
guenhter committed Dec 19, 2018
1 parent e283569 commit 8e1071a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
@@ -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"
Expand All @@ -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
Expand Down
24 changes: 18 additions & 6 deletions run.sh
Expand Up @@ -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

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

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
# 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=:99.0
export DISPLAY=:${displayNumber}.${screenNumber}

echo
cd /data
node /usr/src/app/ -p 80 "$@" &
child=$!
Expand Down

0 comments on commit 8e1071a

Please sign in to comment.