-
-
Save eusonlito/7889622 to your computer and use it in GitHub Desktop.
Based on https://coderwall.com/p/tog9eq but with SCREEN auto detect and some minor fixes
This file contains 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 | |
echo '' | |
XVFB=`which Xvfb` | |
if [ "$XVFB" == '' ]; then | |
echo 'Xvfb is not installed' | |
echo '' | |
exit 1; | |
fi | |
XRANDR=`which xrandr` | |
if [ "$XRANDR" == '' ]; then | |
SCREEN=0 | |
else | |
INFO="$XRANDR -q"; | |
EXPR='Screen ([0-9]+):' | |
if [[ $INFO =~ $EXPR ]]; then | |
SCREEN=$((${BASH_REMATCH[${#BASH_REMATCH[*]} - 1]} + 1)) | |
else | |
SCREEN=0 | |
fi | |
fi | |
XVFBARGS=":$SCREEN -screen $SCREEN 1024x768x24 -ac +extension GLX +render -noreset" | |
PIDFILE=/var/run/xvfb.pid | |
case "$1" in | |
start) | |
echo 'Starting virtual X frame buffer: Xvfb' | |
start-stop-daemon --chuid www-data --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS | |
;; | |
stop) | |
echo 'Stopping virtual X frame buffer: Xvfb' | |
start-stop-daemon --chuid www-data --stop --quiet --pidfile $PIDFILE | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
*) | |
echo 'Usage: '$0' {start|stop|restart}' | |
echo '' | |
exit 1 | |
esac | |
echo '' | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for that.
Took me nearly an hour of debugging, before I noticed your comment 😅
Line 18 also causes an error on my ubuntu 14.04 os:
And then actually responds it started xvfb, when it didn't.
Simply used double quotes and it worked fine afterwards:
INFO="$XRANDR -q";