20090527 an xvfb init script - plembo/onemoretech GitHub Wiki

title: An Xvfb init script link: https://onemoretech.wordpress.com/2009/05/27/an-xvfb-init-script/ author: lembobro description: post_id: 315 created: 2009/05/27 16:03:39 created_gmt: 2009/05/27 16:03:39 comment_status: open post_name: an-xvfb-init-script status: publish post_type: post

An Xvfb init script

Our Oracle Portal developers are using Java AWT to render images and have been running the Xvfb virtual framebuffer server to provide platform graphics support. Because the vfb needs to be running before Portal startup, someone grabbed a quick and dirty init script that looks like it may have come from here (or a common source) and then softlinked to it from an rc_N_.d directory by hand. As the comments inside the script indicate, it can’t be used to shut down the service (because it’s unable to keep track of the runtime process).

My solution was a new init script that integrates with RHEL’s (Red Hat Enterprise Linux) chkconfig.

This code is based on a suggestion by Paul Howarth in this post. The approach is the same one used by Paul to create init scripts for the Fedora Extras bittorrent packages. The cited discussion should be enlightening to anyone trying to create an init script for a binary that wasn’t designed to be run as a daemon.

`

#!/bin/bash
#
# /etc/rc.d/init.d/xvfbd
#
# chkconfig: 345 95 28
# description: Starts/Stops X Virtual Framebuffer server
# processname: Xvfb
#
	
. /etc/init.d/functions
	
[ "${NETWORKING}" = "no" ] && exit 0
	
PROG="/usr/X11R6/bin/Xvfb"
PROG_OPTIONS=":5 -screen 0 640x480x24"
PROG_OUTPUT="/tmp/Xvfb.out"
	
case "$1" in
    start)
        echo -n "Starting : X Virtual Frame Buffer "
        $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 &
        disown -ar
        /bin/usleep 500000
        status Xvfb & >/dev/null && echo_success || echo_failure
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
            /bin/touch /var/lock/subsys/Xvfb
            /sbin/pidof -o  %PPID -x Xvfb > /var/run/Xvfb.pid
        fi
        echo
   		;;
    stop)
        echo -n "Shutting down : X Virtual Frame Buffer"
        killproc $PROG
        RETVAL=$?
        [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb
 /var/run/Xvfb.pid
        echo
        ;;
    restart|reload)
    	$0 stop
    	$0 start
        RETVAL=$?
      	;;
    status)
    	status Xvfb
    	RETVAL=$?
    	;;
    *)
     echo $"Usage: $0 (start|stop|restart|reload|status)"
     exit 1
esac
	
exit $RETVAL

`

After copying the script to /etc/init.d, all that’s necessary to enable it on system restart is to issue the following command as root (assuming you’ve named it xvfbd):

chkconfig --add xvfbd

Copyright 2004-2019 Phil Lembo