Xvfb As A Service

sometimes it’s useful to run a a X app without a display to batch process something, but the app won’t run without an X server to connect to. That’s where X Virtual Frame Buffer Xvfb comes in. It’s everything an X server should be except actually displaying anything. It’s just missing one nicety, by default it doesn’t run as a service, so you’d have to bring it up and tear it back down for every instance that needs the X display. that seems a bit silly, so I wrote a RHEL (and CentOS) chkconfig compatible script to start it up and bring it down gracefully.

#!/bin/bash
#### linux chkconfig settings
# chkconfig: 345 01 99
# description: runs Xvfb on screen :2 at 1024x768x24
case $1 in
'start')
     echo -n "Starting Xvfb..."
     /usr/bin/Xvfb :2 -screen 0 1024x768x24 > /dev/null 2>&1 &
     echo $! > /var/lock/subsys/Xvfb
     RETVAL=$?
     echo
     [ $RETVAL = 0 ]
    ;
'stop')
     echo -n "Stopping Xvfb..."
     kill `cat /var/lock/subsys/Xvfb`
     rm -f /var/lock/subsys/Xvfb
     RETVAL=$?
     echo
     [ $RETVAL = 0 ]
    ;;
*)
    echo "usage: $0 {start|stop}"
    ;;
esac

update: I just found this wordpress plugin to make the script have proper tabs, and get syntax highlighting as a plus. Pretty slick.

Posted in Geek Stuff, Linux


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Powered by WordPress. Designed by Försäkra Online.