Skip to content

Instantly share code, notes, and snippets.

@FlokiTV
Forked from volkovasystems/xvfb-run-safe.sh
Created January 20, 2021 11:51
Show Gist options
  • Save FlokiTV/d1cfdad98e28511d19047eaf337a1c21 to your computer and use it in GitHub Desktop.
Save FlokiTV/d1cfdad98e28511d19047eaf337a1c21 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