scenari
 

Comment passer Xvfb en service sous linux ?

  • Copier-coller le texte suivant dans votre éditeur de texte :

Pour fedora / ubuntu

#!/bin/sh
# chkconfig: 345 91 10
# description: Start/stop/restart the virtual frame buffer based X Server (Xvfb)
#

#==============================================================================
# Configuration
xvfb_path=/usr/bin/Xvfb
xvfb_display=1
killall_path=/usr/bin/killall
#==============================================================================

xvfb_start() {
  if [ -x $xvfb_path ]; then
    echo "Starting Virtual Frame Buffer X Server (Xvfb)."
    $xvfb_path :$xvfb_display -screen 0 800x600x16 &
  else
    echo "Error: Could not find $xvfb_path. Cannot start Xvfb."
  fi
}

xvfb_stop() {
  if [ -x $killall_path ]; then
    echo "Stopping Virtual Frame Buffer X Server (Xvfb)."
    $killall_path Xvfb 2> /dev/null
  else
    echo "Error: Could not find $killall_path. Cannot stop Xvfb."
  fi
}

case "$1" in
  'start')
    xvfb_start
    ;;
  'stop')
    xvfb_stop
    ;;
  'restart')
    xvfb_stop
    sleep 1
    xvfb_start
    ;;
  *)
    if [ -x /usr/bin/basename ]; then
      echo "usage: `/usr/bin/basename $0` start|stop|restart"
    else
      echo "usage: $0 start|stop|restart"
    fi
esac
  • Editez les lignes indiquant :
    • le chemin de Xvfb,
    • le numéro du DISPLAY sur lequel démarrer Xvfb,
    • le chemin de la commande killall.
  • Sauvez le fichier dans /etc/init.d sous le nom xvfb (ce répertoire est standard sur les distributions récentes)
  • Rendez le script exécutable: chmod a+x xvfb
  • Ajouter xvfb au bon runlevel : chkconfig --add xvfb