wiki:servicetomcat

Comment passer SCENARIserver en service sous linux ?

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

pour fedora

# This is the init script for starting up SCENARIserver
#
# chkconfig: 345 90 10
# description: Starts and stops the Tomcat daemon of SCENARIserver.
#

#==============================================================================
# Server configuration

# Name of the server (used when printing out status).
serverName=SCENARIserver

# Set this to the path of the tomcat folder.
tomcat=/opt/SCENARIserver/tomcat

# user to run the tomcat server as
# (you have to create this user yourself, he must be owner or have write permission
# on tomcat webapp dir, scenari workshop dir and other temporary dirs)
runasuser=root

# Set this if you need to specify a specific JRE.
export JAVA_HOME=/opt/SCENARIserver/jre

# SCENARIserver needs a minimum of 256Mb of heap space.
heapspace=512M

# Extra JVM options
extra_options=""

# JVM options
opts_start=" -Xms$heapspace -Xmx$heapspace -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true $extra_options"
opts_stop=" -Xms64M -Xmx128M "

# Path to tomcat pid file.
export CATALINA_PID="$tomcat/tomcat.pid"

# Shutdown timeout before tomcat is killed (in seconds)
kill_timeout=30

#==============================================================================
# OpenOffice Configuration

# Set DISPLAY variable if you want OpenOffice to use a specific display
export DISPLAY="localhost:1.0"

# If set this stops the recovery dialog prompting you as OO.o starts up
# after a crash - instead the recovery files are just silently
# accumulated.
export OOO_DISABLE_RECOVERY=1

#==============================================================================

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh

start() {
    [ -x $startup ] || exit 5
    # Tomcat pid checks
    if [ -f $CATALINA_PID ] ; then
     if [ "$(ps -p `cat $CATALINA_PID` | wc -l)" -gt 1 ]; then
        # Tomcat process is still running
        echo "ERROR: $serverName seems to be already running as process `cat $CATALINA_PID`"
        exit 1
      else
        # Tomcat process not running, but lock file not deleted?
        echo "WARNING: orphan lock file. Lock file deleted."
        rm $CATALINA_PID
      fi
    fi
    echo -n $"Starting $serverName: "
    su -s /bin/bash -c $startup $runasuser
    retval=$?
    echo
    return $retval
}

stop() {
    echo -n $"Stopping $serverName: "
    # Kill all OpenOffice instances run but the tomcat user...
    pkill -9 -u $runasuser soffice
    su -s /bin/bash -c "$shutdown $kill_timeout -force" $runasuser
    retval=$?
    echo 
    return $retval
}

restart(){
  stop
  start
}

# See how we were called.
case "$1" in
start)
 start
 ;;
stop)
 stop
 ;;
status)
# This doesn't work ;)
# status SCENARIserver
 ;;
restart)
 restart
 ;;
*)
 echo $"Usage: $0 {start|stop|restart}"
 exit 1
esac

exit 0

pour debian / ubuntu

#! /bin/bash
# This is the init script for starting up SCENARIserver.
#
# description: Starts and stops the Tomcat daemon of SCENARIserver
#

#==============================================================================
# Server configuration

# Name of the server (used when printing out status).
serverName=SCENARIserver

# Set this to the path of the tomcat folder.
tomcat=/opt/SCENARIserver/tomcat

# user to run the tomcat server as
# (you have to create this user yourself, he must be owner or have write permission
# on tomcat webapp dir, scenari workshop dir and other temporary dirs)
runasuser=root

# Set this if you need to specify a specific JRE.
export JAVA_HOME=/opt/SCENARIserver/jre
export PATH="$PATH:/usr/bin"

# SCENARIserver needs a minimum of 256Mb of heap space.
heapspace=512M

# Extra JVM options
extra_options=""

# JVM options
opts_start=" -Xms$heapspace -Xmx$heapspace -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true $extra_options"
opts_stop=" -Xms64M -Xmx128M "

# Path to tomcat pid file.
export CATALINA_PID="$tomcat/tomcat.pid"

# Shutdown timeout before tomcat is killed (in seconds)
kill_timeout=30

#==============================================================================
# OpenOffice Configuration

# Set DISPLAY variable if you want OpenOffice to use a specific display
export DISPLAY=":1.0"

# If set this stops the recovery dialog prompting you as OO.o starts up
# after a crash - instead the recovery files are just silently
# accumulated.
export OOO_DISABLE_RECOVERY=1

export UNO_PATH=/usr/lib/openoffice/program/

#==============================================================================

startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh

. /lib/lsb/init-functions

start(){
    # Tomcat pid checks
    if [ -f $CATALINA_PID ] ; then
     if [ "$(ps -p `cat $CATALINA_PID` | wc -l)" -gt 1 ]; then
        # Tomcat process is still running
        echo "ERROR: $serverName seems to be already running as process `cat $CATALINA_PID`"
        exit 1
      else
        # Tomcat process not running, but lock file not deleted?
        echo "WARNING: orphan lock file. Lock file deleted."
        rm $CATALINA_PID
      fi
    fi
    log_begin_msg "Starting $serverName..."
    export JAVA_OPTS="$opts_start"
    su -s /bin/bash -c $startup $runasuser
    log_end_msg $?
}
stop(){
    log_begin_msg "Stoping $serverName..."
    export JAVA_OPTS="$opts_stop"
    # Kill all OpenOffice instances run but the tomcat user...
    pkill -9 -u $runasuser soffice
    su -s /bin/bash -c "$shutdown $kill_timeout -force" $runasuser
    log_end_msg $?
}
restart(){
    stop
    start
}

# See how we were called.
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
status)
    # status SCENARIserver
    echo "Status: not implemented"
    ;;
restart)
    restart
    ;;
*)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit 0

Procédure d'installation

Personnalisation

Éditez les lignes indiquant :

  • le répertoire de tomcat, (variable tomcat).
  • le répertoire de la JRE, (variable JAVA_HOME).
  • le répertoire de openoffice, (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 openoffice.

Installation

  • Sauvez le fichier dans /etc/init.d sous le nom SCENARIserver (ce répertoire est standard sur les distributions récentes)
  • Rendez 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