Configuration de Tomcat

Pour permettre à des webapps SCENARIserver de fonctionner correctement dans le serveur de servlets Tomcat il est nécessaire d'y apporter certaines modifications de paramétrage.

AttentionSécurité

A l'heure actuel, Les webapps SCENARIserver ne sont pas compatible avec le "Security Manager" de Tomcat. Il est important de ne pas activer le module "Security Manager" lors du démarrage de Tomcat.

Par défaut le "Security Manager" n'est pas actif, cependant il faut être vigilant sur ce point lors de l'usage de versions packagées de Tomcat sous Linux.

ComplémentUsage d'un proxy Apache

Il est possible de cacher Tomcat derrière un proxy Apache. Ceci permet entre autres d'accéder à SCENARIserver sur le port 80 même si vous avez déjà une serveur web Apache d'installé. Il y a plusieurs façons de mettre en place un proxy Apache vers Tomcat, le plus simple et le seul qui à été testé avec succès avec SCENARIserver est l'usage du module Apache mod_proxy :

ConseilTomcat sous Debian / Ubuntu

Si vous utilisez la version packagée de Tomcat, tous les fichiers de configuration de Tomcat sont dans /etc/tomcat6.

Il convient alors de remplacer les chemins [TOMCAT_HOME]/conf dans les procédures ci-dessous par /etc/tomcat6/conf.

ProcédureParamétrer la mémoire RAM allouée à l'application

  1. Si Tomcat est lancé, le stopper (cf procédure dans le présent guide) ;

  2. Ouvrir le fichier [TOMCAT_HOME]/bin/catalina.sh ;

  3. Créer la variable JAVA_OPTS en début de fichier ;

    ExempleExemple pour 1024Mo

    JAVA_OPTS="-Xms1024M -Xmx1024M $JAVA_OPTS"

ProcédureCharger les librairies LibreOffice

L'utilisation de plusieurs webApp SCENARI sur le même serveur Tomcat nécessite un paramétrage permettant le partage de l'accès à LibreOffice.

  1. Ouvrir le fichier [TOMCAT_HOME]/conf/catalina.properties;

  2. Modifier la ligne "shared.loader" pour y déclarer les chemins des librairies LibreOffice jurt.jar, ridl.jar et unoil.jar.

    ExempleExemple de configuration windows

    shared.loader=file:///D:/Program Files (x86)/LibreOffice 4/URE/java/jurt.jar,file:///D:/Program Files (x86)/LibreOffice 4/URE/java/ridl.jar,file:///D:/Program Files (x86)/LibreOffice 4/Basis/program/classes/unoil.jar

    ExempleExemple de configuration linux

    shared.loader=/opt/libreoffice4.3/ure/share/java/jurt.jar,/opt/libreoffice4.3/ure/share/java/ridl.jar,/opt/libreoffice4.3/program/classes/unoil.jar

ProcédureConnecteurs Tomcat

Le connecteur Tomcat doit être utilisé pour les spécification suivantes :

  • Spécification du port (8080 par défaut) ;
  • Encodage des URLs ;
  • Taille des buffers ;
  • ...

Pour éviter des problèmes d'encodage de nom de fichier il est important de forcer Tomcat à traiter toutes les url en UTF-8.

  1. Ouvrir le fichier [TOMCAT_HOME]/conf/server.xml avec un éditeur XML (type notepad);

    Compléments

    Remarque

    Assurez-vous de bien disposer des droits d'écriture sur ce fichier. Si tel n'est pas le cas, et que vous disposez des droits de remplacement uniquement, copier/coller au préalable le fichier sur votre bureau le temps de le modifier.

  2. Modifier ou ajouter un Connector sur le protocole HTTP/1.1.

    • Pour modifier le port, utiliser l'attribut port ;
    • Pour éviter des problèmes d'encodage de nom de fichier il est important de forcer Tomcat à traiter toutes les url en UTF-8. Ajouter donc le paramètre URIEncoding="UTF-8"
    • Pour étendre la taille autorisée des entêtes HTTP, ajouter le paramètre maxHttpHeaderSize="65536"

    Exemple complet de paramétrage : <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" maxHttpHeaderSize="65536"/>

    Compléments

ProcédureSuppression des éléments non utilisés de Tomcat

Tomcat apporte un lot d'outils lors de son installation standard non utilisés, ou qui pourraient apporter des faille de sécurité. Il est donc conseillé de les supprimer.

  1. Supprimer les répertoires "docs", "examples", "host-manager", "manager " dans [TOMCAT_HOME]/webapps.

    Compléments

    Purge des webapps par défaut de Tomcat

  2. Ouvrir le fichier [TOMCAT_HOME]/conf/server.xml, et supprimer le connector "AJP "

    Supprimer ou commenter la ligne <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

ProcédureDémarrer Tomcat

Cette procédure décrit comment démarrer le serveur d'application Tomcat.

RemarqueConditions d'utilisation

Tomcat a été paramétré pour démarrer automatiquement lors de l'initialisation du serveur. Cette procédure n'est donc à utiliser qu'en cas de dysfonctionnement rencontré sur le serveur d'application.

  1. Exécuter la commande [TOMCAT_HOME]/bin/catalina.sh start

    Compléments

    Complément

    Il faut être connecté avec votre utilisateur pour tomcat pour réaliser cette action

    RemarqueTest de bon fonctionnement

    Une fois démarré, la requête suivante doit répondre http://127.0.0.1:8081/scserver40/s/chain/u/ping (page blanche).

ProcédureStopper Tomcat

Cette procédure décrit comment arrêter le serveur d'application Tomcat.

  1. Exécuter la commande [TOMCAT_HOME]/bin/catalina.sh stop ;

    Compléments

    Complément

    Il faut être connecté avec votre utilisateur pour tomcat pour réaliser cette action

ProcédurePasser Tomcat (SCENARIserver) en service

  1. Copier-coller le code suivant dans un éditeur de texte

    Compléments

    Red Hat, Fedora, CentOS

    1
    # This is the init script for starting up SCENARIserver
    2
    #
    3
    # chkconfig: 345 90 10
    4
    # description: Starts and stops the Tomcat daemon of SCENARIserver.
    5
    #
    6
    7
    #==============================================================================
    8
    # Server configuration
    9
    10
    # Name of the server (used when printing out status).
    11
    serverName=SCENARIserver
    12
    13
    # Set this to the path of the tomcat folder.
    14
    tomcat=/opt/SCENARIserver/tomcat
    15
    16
    # user to run the tomcat server as
    17
    # (you have to create this user yourself, he must be owner or have write permission
    18
    # on tomcat webapp dir, scenari workshop dir and other temporary dirs)
    19
    runasuser=root
    20
    21
    # Set this if you need to specify a specific JRE.
    22
    export JAVA_HOME=/opt/SCENARIserver/jre
    23
    24
    # SCENARIserver needs a minimum of 256Mb of heap space.
    25
    heapspace=512M
    26
    27
    # Extra JVM options
    28
    extra_options=""
    29
    30
    # JVM options
    31
    opts_start=" -Xms$heapspace -Xmx$heapspace -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true $extra_options"
    32
    opts_stop=" -Xms64M -Xmx128M "
    33
    34
    # Path to tomcat pid file.
    35
    export CATALINA_PID="$tomcat/tomcat.pid"
    36
    37
    # Shutdown timeout before tomcat is killed (in seconds)
    38
    kill_timeout=30
    39
    40
    #==============================================================================
    41
    # LibreOffice Configuration
    42
    43
    # Set DISPLAY variable if you want LibreOffice to use a specific display
    44
    export DISPLAY="localhost:1.0"
    45
    46
    # If set this stops the recovery dialog prompting you as OO.o starts up
    47
    # after a crash - instead the recovery files are just silently
    48
    # accumulated.
    49
    export OOO_DISABLE_RECOVERY=1
    50
    51
    #==============================================================================
    52
    53
    # Source function library.
    54
    . /etc/rc.d/init.d/functions
    55
    56
    # Get config.
    57
    . /etc/sysconfig/network
    58
    59
    # Check that networking is up.
    60
    [ "${NETWORKING}" = "no" ] && exit 0
    61
    62
    startup=$tomcat/bin/startup.sh
    63
    shutdown=$tomcat/bin/shutdown.sh
    64
    65
    start() {
    66
        [ -x $startup ] || exit 5
    67
        # Tomcat pid checks
    68
        if [ -f $CATALINA_PID ] ; then
    69
         if [ "$(ps -p `cat $CATALINA_PID` | wc -l)" -gt 1 ]; then
    70
            # Tomcat process is still running
    71
            echo "ERROR: $serverName seems to be already running as process `cat $CATALINA_PID`"
    72
            exit 1
    73
          else
    74
            # Tomcat process not running, but lock file not deleted?
    75
            echo "WARNING: orphan lock file. Lock file deleted."
    76
            rm $CATALINA_PID
    77
          fi
    78
        fi
    79
        echo -n $"Starting $serverName: "
    80
        export JAVA_OPTS="$opts_start"
    81
        su -s /bin/bash -c $startup $runasuser
    82
        retval=$?
    83
        echo
    84
        return $retval
    85
    }
    86
    87
    stop() {
    88
        echo -n $"Stopping $serverName: "
    89
        # Kill all LibreOffice instances run but the tomcat user...
    90
        pkill -9 -u $runasuser soffice
    91
        export JAVA_OPTS="$opts_stop"
    92
        su -s /bin/bash -c "$shutdown $kill_timeout -force" $runasuser
    93
        retval=$?
    94
        echo 
    95
        return $retval
    96
    }
    97
    98
    restart(){
    99
      stop
    100
      start
    101
    }
    102
    103
    # See how we were called.
    104
    case "$1" in
    105
    start)
    106
     start
    107
     ;;
    108
    stop)
    109
     stop
    110
     ;;
    111
    status)
    112
    # This doesn't work ;)
    113
    # status SCENARIserver
    114
     ;;
    115
    restart)
    116
     restart
    117
     ;;
    118
    *)
    119
     echo $"Usage: $0 {start|stop|restart}"
    120
     exit 1
    121
    esac
    122
    123
    exit 0

    Debian, Ubuntu, Mint

    1
    #! /bin/bash
    2
    # This is the init script for starting up SCENARIserver.
    3
    #
    4
    # description: Starts and stops the Tomcat daemon of SCENARIserver
    5
    #
    6
    7
    #==============================================================================
    8
    # Server configuration
    9
    10
    # Name of the server (used when printing out status).
    11
    serverName=SCENARIserver
    12
    13
    # Set this to the path of the tomcat folder.
    14
    tomcat=/opt/SCENARIserver/tomcat
    15
    16
    # user to run the tomcat server as
    17
    # (you have to create this user yourself, he must be owner or have write permission
    18
    # on tomcat webapp dir, scenari workshop dir and other temporary dirs)
    19
    runasuser=root
    20
    21
    # Set this if you need to specify a specific JRE.
    22
    export JAVA_HOME=/opt/SCENARIserver/jre
    23
    export PATH="$PATH:/usr/bin"
    24
    25
    # SCENARIserver needs a minimum of 256Mb of heap space.
    26
    heapspace=512M
    27
    28
    # Extra JVM options
    29
    extra_options=""
    30
    31
    # JVM options
    32
    opts_start=" -Xms$heapspace -Xmx$heapspace -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true $extra_options"
    33
    opts_stop=" -Xms64M -Xmx128M "
    34
    35
    # Path to tomcat pid file.
    36
    export CATALINA_PID="$tomcat/tomcat.pid"
    37
    38
    # Shutdown timeout before tomcat is killed (in seconds)
    39
    kill_timeout=30
    40
    41
    #==============================================================================
    42
    # LibreOffice Configuration
    43
    44
    # Set DISPLAY variable if you want LibreOffice to use a specific display
    45
    export DISPLAY=":1.0"
    46
    47
    # If set this stops the recovery dialog prompting you as OO.o starts up
    48
    # after a crash - instead the recovery files are just silently
    49
    # accumulated.
    50
    export OOO_DISABLE_RECOVERY=1
    51
    52
    export UNO_PATH=/usr/lib/libreoffice/program/
    53
    54
    #==============================================================================
    55
    56
    startup=$tomcat/bin/startup.sh
    57
    shutdown=$tomcat/bin/shutdown.sh
    58
    59
    . /lib/lsb/init-functions
    60
    61
    start(){
    62
        # Tomcat pid checks
    63
        if [ -f $CATALINA_PID ] ; then
    64
         if [ "$(ps -p `cat $CATALINA_PID` | wc -l)" -gt 1 ]; then
    65
            # Tomcat process is still running
    66
            echo "ERROR: $serverName seems to be already running as process `cat $CATALINA_PID`"
    67
            exit 1
    68
          else
    69
            # Tomcat process not running, but lock file not deleted?
    70
            echo "WARNING: orphan lock file. Lock file deleted."
    71
            rm $CATALINA_PID
    72
          fi
    73
        fi
    74
        log_begin_msg "Starting $serverName..."
    75
        export JAVA_OPTS="$opts_start"
    76
        su -s /bin/bash -c $startup $runasuser
    77
        log_end_msg $?
    78
    }
    79
    stop(){
    80
        log_begin_msg "Stoping $serverName..."
    81
        export JAVA_OPTS="$opts_stop"
    82
        # Kill all LibreOffice instances run but the tomcat user...
    83
        pkill -9 -u $runasuser soffice
    84
        su -s /bin/bash -c "$shutdown $kill_timeout -force" $runasuser
    85
        log_end_msg $?
    86
    }
    87
    restart(){
    88
        stop
    89
        start
    90
    }
    91
    92
    # See how we were called.
    93
    case "$1" in
    94
    start)
    95
        start
    96
        ;;
    97
    stop)
    98
        stop
    99
        ;;
    100
    status)
    101
        # status SCENARIserver
    102
        echo "Status: not implemented"
    103
        ;;
    104
    restart)
    105
        restart
    106
        ;;
    107
    *)
    108
        echo "Usage: $0 {start|stop|restart}"
    109
        exit 1
    110
    esac
    111
    112
    exit 0
  2. ÉditeR les lignes indiquant :

    Compléments
    • le répertoire de tomcat, (variable tomcat) ;
    • le répertoire de la JRE, (variable JAVA_HOME) ;
    • le répertoire de libreoffice, (variable UNO_PATH) ;
    • les options de lancement de la JRE : la mémoire alloué à tomcat dans cet exemple est 512M. Adaptez les valeurs -Xms et -Xmx à votre contexte ;
    • le display utilisable pour libreoffice ;
  3. Installation

    Compléments
    • Sauver le fichier dans /etc/init.d sous le nom SCENARIserver (ce répertoire est standard sur les distributions récentes)

    • Rendre le script exécutable: chmod a+x SCENARIserver

    • Ajouter SCENARIserver au bon runlevel :

      • sous Fedora : chkconfig --add SCENARIserver

      • sous Ubuntu : update-rc.d SCENARIserver defaults 90 10