Skip to content

Instantly share code, notes, and snippets.

@volkovasystems
Created October 28, 2016 09:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save volkovasystems/f4661b87d44c89275a48631fdabee41d to your computer and use it in GitHub Desktop.
Save volkovasystems/f4661b87d44c89275a48631fdabee41d to your computer and use it in GitHub Desktop.
xvfb-run-safe
#!/bin/bash
# allow settings to be updated via environment
: "${xvfb_lockdir:=$HOME/.xvfb-locks}"
: "${xvfb_display_min:=99}"
: "${xvfb_display_max:=599}"
mkdir -p -- "$xvfb_lockdir" || exit
i=$xvfb_display_min # minimum display number
while (( i < xvfb_display_max )); do
if [ -f "/tmp/.X$i-lock" ]; then
(( ++i )); continue
fi
exec 5>"$xvfb_lockdir/$i" || continue
if flock -x -n 5; then
exec xvfb-run --server-num="$i" "$@" || exit
fi
(( i++ ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment