Install the Virtual Frame Buffer on Linux

From Wiki
Revision as of 22:37, 19 August 2010 by Ebasso (talk | contribs) (New page: Install Xvfb If the name of your machine is <YourServerName>, use the following: [root@<YourServerName> R-2.6.1]# yum update xorg-x11-server-Xorg [root@<YourServerName> R-2.6.1]# yum ins...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Install Xvfb If the name of your machine is <YourServerName>, use the following:

[root@<YourServerName> R-2.6.1]# yum update xorg-x11-server-Xorg [root@<YourServerName> R-2.6.1]# yum install xorg-x11-server-Xvfb.x86_64

Start and Test Xvfb To start Xvfb, use the following command:

[root@<YourServerName> R-2.6.1]# /usr/bin/Xvfb :2 -nolisten tcp -shmem

This starts a Display on servernumber = 2 and screen number = 0.

To test whether the X11, PNG and JPEG devices are available in R:

[root@<YourServerName> R-2.6.1]# export DISPLAY=:2.0 [root@<YourServerName> R-2.6.1]# bin/R

You will see many lines of output. At the ">" prompt, run the capabilities() command. It will tell you whether the X11, JPEG and PNG devices are functioning. The following example output shows success:

> capabilities()

  jpeg png tcltk X11 http/ftp sockets libxml fifo 
  TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
cledit iconv NLS profmem 
  TRUE TRUE TRUE FALSE

Make configuration changes to ensure that Xvfb is started at boot-time You need to make sure that Xvfb runs at all times on the machine or R will not function as needed. There are many ways to do this. This example uses a simple start/stop script and treats it as a service.

The script:

[root@<YourServerName> R-2.6.1]# cd /etc/init.d [root@<YourServerName> init.d]# vi xvfb

  #!/bin/bash 
  # 
  # /etc/rc.d/init.d/xvfb 
  # 
  # Author: Brian Connolly (LabKey.org) 
  # 
  # chkconfig: 345 98 90 
  # description: Starts Virtual Framebuffer process to enable the  
  # LabKey server to use R. 
  # 
  #

XVFB_OUTPUT=/usr/local/labkey/Xvfb.out XVFB=/usr/bin/Xvfb XVFB_OPTIONS=":2 -nolisten tcp -shmem"

  1. Source function library. . /etc/init.d/functions
  start() {            echo -n "Starting : X Virtual Frame Buffer "            $XVFB $XVFB_OPTIONS >>$XVFB_OUTPUT 2>&1&            RETVAL=$?            echo            return $RETVAL    }

stop() { echo -n "Shutting down : X Virtual Frame Buffer" echo killproc Xvfb echo return 0 }

case "$1" in start) start  ;; stop) stop  ;; *) echo "Usage: xvfb {start|stop}" exit 1  ;; esac exit $?

Now test the script with the standard:

[root@<YourServerName> etc]# /etc/init.d/xvfb start [root@<YourServerName> etc]# /etc/init.d/xvfb stop [root@<YourServerName> etc]# /etc/init.d/xvfb

This should work without a hitch.

Note: Any error messages produced by Xvfb will be sent to the file set in

$XVFB_OUTPUT.

If you experience problems, these messages can provide further guidance.

The last thing to do is to run chkconfig to finish off the configuration. This creates the appropriate start and kills links in the rc#.d directories. The script above contains a line in the header comments that says "# chkconfig: 345 98 90". This tells the chkconfig tool that xvfb script should be executed at runlevels 3,4,5. It also specifies the start and stop priority (98 for start and 90 for stop). You should change these appropriately.

[root@<YourServerName> init.d]# chkconfig --add xvfb

Check the results:

[root@<YourServerName> init.d]# chkconfig --list xvfb xvfb 0:off 1:off 2:off 3:on 4:on 5:on 6:off

Verify that the appropriate soft links have been created:

[root@<YourServerName> init.d]# ls -la /etc/rc5.d/ | grep xvfb lrwxrwxrwx 1 root root 14 2008-01-22 18:05 S98xvfb -> ../init.d/xvfb

Start the Xvfb Process and Setup the DISPLAY Env Variable Start the process using:

[root@<YourServerName> init.d]# /etc/init.d/xvfb start

Now you will need to the set the DISPLAY env variable for the user. This is the DISPLAY variable that is used to run the TOMCAT server. Add the following the .bash_profile for this user. On this serer, the TOMCAT process is run by the user tomcat

[root@<YourServerName> ~]# vi ~tomcat/.bash_profile [added]

  1. Set DISPLAY variable for using LabKey and R.

DISPLAY=:2.0 export DISPLAY

Restart the LabKey Server or it will not have the DISPLAY variable set On this server, we have created a start/stop script for TOMCAT within /etc/init.d. So I will use that to start and stop the server