Nick's Tech Blog: Fedora > install Xvfb as a service

Pages

Thursday, September 22, 2011

Fedora > install Xvfb as a service

Problem

I required Xvfb to be installed, and running as a service on a server.

Assumptions: you know how to use chkconfig, yum, vi and chmod.

Solution
  1. yum install xorg-x11-server-Xvfb
  2. vi /etc/init.d/xvfbd (copy contents below into the file, and save it)
  3. chmod 755 /etc/init.d/xvfbd (now we have a service)
  4. chkconfig --add xvfbd
  5. chkconfig --level 2345 xvfbd on

You can now start your service with:
sudo service xvfbd start

Check it's running:
ps -ef | grep Xvfb

Check it's listed to startup automatically for runlevels 2,3,4,5:
chkconfig --list


/etc/init.d/xvfbd

#!/bin/bash
#
# description: Xvfb server
#


# Get function from functions library
. /etc/init.d/functions


# Start the service Xvfb
start() {
        echo -n "Starting Xvfb server: "
        /usr/bin/Xvfb &
        ### Create the lock file ###
        touch /var/lock/subsys/Xvfb
        success $"Xvfb server startup"
        echo
}


# Restart the service Xvfb
stop() {
        echo -n "Stopping Xvfb server: "
        killproc Xvfb
        ### Now, delete the lock file ###
        rm -f /var/lock/subsys/Xvfb
        echo
}


### main logic ###
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status Xvfb
        ;;
  restart|reload|condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac


exit 0

See also:
http://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

3 comments:

  1. [root@media ~]# chkconfig --add xvfbd
    service xvfbd does not support chkconfig

    Starting Xvfb server: [ OK ]
    [root@media ~]# (EE) AIGLX error: dlopen of /usr/lib/dri/swrastg_dri.so failed (/usr/lib/dri/swrastg_dri.so: cannot open shared object file: No such file or directory)
    (EE) GLX: could not load software renderer

    ReplyDelete
  2. http://prefetch.net/blog/index.php/2007/04/01/making-rc-scripts-chkconfig-aware/

    ReplyDelete
  3. Hello
    With Fedora 17 and Fedora 18, init.d has been replaced with systemd and service files.
    How to adapt your script to make it compatible with this new method?

    ReplyDelete