Instalando o Virtual Frame Buffer no Linux: Difference between revisions

From Wiki
No edit summary
No edit summary
Line 39: Line 39:
  vi xvfb  
  vi xvfb  


  #!/bin/bash  
#!/bin/bash  
  #  
#  
  # /etc/rc.d/init.d/xvfb  
# /etc/rc.d/init.d/xvfb  
  #  
#  
  # Author: Brian Connolly (LabKey.org)  
# Author: Brian Connolly (LabKey.org)  
  #  
#  
  # chkconfig: 345 98 90  
# chkconfig: 345 98 90  
  # description: Starts Virtual Framebuffer process to enable the   
# description: Starts Virtual Framebuffer process to enable the   
  # LabKey server to use R.  
# LabKey server to use R.  
  #  
#  
   #
   #
 
XVFB_OUTPUT=/usr/local/labkey/Xvfb.out
XVFB_OUTPUT=/usr/local/labkey/Xvfb.out   XVFB=/usr/bin/Xvfb   XVFB_OPTIONS=":2 -nolisten tcp -shmem"
XVFB=/usr/bin/Xvfb
 
XVFB_OPTIONS=":2 -nolisten tcp -shmem"
# Source function library.    . /etc/init.d/functions
 
# Source function library.     
  start() {           echo -n "Starting : X Virtual Frame Buffer "            $XVFB $XVFB_OPTIONS >>$XVFB_OUTPUT 2>&1&           RETVAL=$?            echo            return $RETVAL   }
. /etc/init.d/functions
 
stop() {           echo -n "Shutting down : X Virtual Frame Buffer"           echo           killproc Xvfb           echo           return 0   }
start() {
 
    echo -n "Starting : X Virtual Frame Buffer "             
case "$1" in       start)           start           ;;       stop)           stop           ;;       *)           echo "Usage: xvfb {start|stop}"           exit 1           ;;   esac   exit $?
    $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:
Now test the script with the standard:


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


This should work without a hitch.
This should work without a hitch.
Line 71: Line 97:
Note: Any error messages produced by Xvfb will be sent to the file set in
Note: Any error messages produced by Xvfb will be sent to the file set in


$XVFB_OUTPUT.
$XVFB_OUTPUT.


If you experience problems, these messages can provide further guidance.
If you experience problems, these messages can provide further guidance.
Line 77: Line 103:
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.
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
chkconfig --add xvfb


Check the results:
Check the results:


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


Verify that the appropriate soft links have been created:
Verify that the appropriate soft links have been created:


[root@<YourServerName> init.d]# ls -la /etc/rc5.d/ | grep xvfb  
ls -la /etc/rc5.d/ | grep xvfb  
lrwxrwxrwx 1 root root 14 2008-01-22 18:05 S98xvfb -> ../init.d/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 Xvfb Process and Setup the DISPLAY Env Variable
Start the process using:
Start the process using:


[root@<YourServerName> init.d]# /etc/init.d/xvfb start
/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
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  
vi ~tomcat/.bash_profile  
[added]
 
# Set DISPLAY variable for using LabKey and R.  
# Set DISPLAY variable for using LabKey and R.  
DISPLAY=:2.0  
DISPLAY=:2.0  
export DISPLAY
export DISPLAY


Restart the LabKey Server or it will not have the DISPLAY variable set
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
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

Revision as of 16:43, 23 July 2024

Instalando os pacotes Necessários

Instale os seguintes pacotes ao seu linux:

 - xorg-x11-server-Xorg
 - xorg-x11-server-Xvfb

se você estiver utilizando o yum faça o seguinte:

yum -y install xorg-x11-server-Xorg xorg-x11-server-Xvfb

Start and Test Xvfb

To start Xvfb, use the following command:

/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:

export DISPLAY=:2.0 


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:

cd /etc/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"

# 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:

/etc/init.d/xvfb start 
/etc/init.d/xvfb stop 
/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.

chkconfig --add xvfb

Check the results:

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:

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:

/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

vi ~tomcat/.bash_profile 
# 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