Created
November 13, 2015 19:02
-
-
Save tullmann/476cc71169295d5c3fe6 to your computer and use it in GitHub Desktop.
wait for an X11 server to be ready (good for running under XVFB when testing chrome)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# waitForX [<cmd> [<arg> ...]] | |
# | |
# Wait for X Server to be ready, then run the given command once X server | |
# is ready. (Or simply return if no command is provided.) | |
# | |
function LOG { | |
echo $(date -R): $0: $* | |
} | |
if [ -z "$DISPLAY" ]; then | |
LOG "FATAL: No DISPLAY environment variable set. No X." | |
exit 13 | |
fi | |
LOG "Waiting for X Server $DISPLAY to be available" | |
MAX=120 # About 60 seconds | |
CT=0 | |
while ! xdpyinfo >/dev/null 2>&1; do | |
sleep 0.50s | |
CT=$(( CT + 1 )) | |
if [ "$CT" -ge "$MAX" ]; then | |
LOG "FATAL: $0: Gave up waiting for X server $DISPLAY" | |
exit 11 | |
fi | |
done | |
LOG "X is available" | |
if [ -n "$1" ]; then | |
exec "$@" | |
fi | |
#eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment