Solving XPlanner's $DISPLAY issues on a headless Linux (Debian) server

A month or so ago at work we started playing around with XPlanner, a project planning and tracking tool for eXtreme Programming (XP) teams. I downloaded it to my Ubuntu workstation, unzipped it and ran startup_xplanner.sh. Everything worked fine, all the graphs displayed, all the reports, etc.

We then decided that we would start to use it seriously and so it needed moving to a central server. This is when our problems started. We started to get errors such as:

java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
.

This was due to XPlanner now running on a headless server but it requires the Java AWT graphics libraries to draw the graphs. These in turn use the underlying system's X server, which requires some kind of X server running.

After some investigation I found Xvfb, an X server virtual framebuffer which will happily run on a headless server.

To install Xvfb, login as root and then apt-get the package:

apt-get install xvfb

We now need to create a couple of start/stop scripts so that both Xvfb and XPlanner are started when the system reboots.

Create a file in /etc/init.d called xvfb with the contents below:

#!/bin/bash

if [ -z "$1" ]; then
echo "`basename $0` {start|stop}"
exit
fi

case "$1" in
start)
/usr/bin/X11/Xvfb :0.0 &
;;

stop)
killall Xvfb
;;
esac

Create another file in /etc/init.d called xplanner with the contents below:

#!/bin/bash

DISPLAY=:0.0
export DISPLAY

JAVA_HOME=/usr/local/tools/j2sdk1.4.2_04
export JAVA_HOME

XPLANNER_HOME=/usr/local/tools/xplanner-0.7b4-standalone

if [ -z "$1" ]; then
echo "`basename $0` {start|stop}"
exit
fi

cd $XPLANNER_HOME

case "$1" in
start)
$XPLANNER_HOME/startup_xplanner.sh
;;

stop)
$XPLANNER_HOME/shutdown_xplanner.sh
;;
esac

cd -

We need to ensure that Xvfb is up and running before XPlanner attempts to start, so we need to force the order in which the start/stop scripts are executed:

update-rc.d xvfb defaults 10
update-rc.d xplanner defaults 80

Now reboot the server and you should have an auto-starting XPlanner which actually displays the graphs!

Technorati Tags: , , , , , ,