Apache-tomcat-7.0.42
Java 1.7.0_45-b18
CentOS Linux release 7.2.1511

I have been using various releases of Apache Tomcat as a standalone
web server and servlet container
to serve a commercial web-app written entirely in Java for the past 4
years. Recently my server host informed me that I needed to
move to their 'cloud'.

This meant moving from a CentOS release 5.2 system that used a
SysV-style init script in /etc/rc.d/init.d with symbolic links in
rc2.d, rc3.d, rc4.d and rc5.d
to a CentOS Linux release 7.2.1511 system that used a systemd init system

The init.d script was called tomcat7 and is listed at the end of this message.

Tomcat is employed as a stand alone web server binding to the default
port for inbound non-encrypted http traffic which is port 80.
Due to the restricions placed on privileged ports (< 1024) by UNIX
like systems this required the use of an additional component.

The component chosen was jsvc
(http://commons.apache.org/proper/commons-daemon/jsvc.html)
Tomcat documentation re jsvc
(https://tomcat.apache.org/tomcat-7.0-doc/setup.html)

The first attempt at getting Tomcat to start after a system reboot
consisted of calling the original inid.d script.

# touch /etc/systemd/system/tomcat.service

tomcat.service began life as follows

[Unit]
Description=The Jakarta Apache/Tomcat Server
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/init.d/tomcat7 start
ExecStop=/etc/rc.d/init.d/tomcat7 stop

[Install]
WantedBy=multi-user.target

This and many other versions that called the original init.d script
failed with various systemd error codes
The reason(s) are as yet not fully understood.

The final solution shows the invocation arguments passed to jsvc in
longhand, this is the only way we could get it to work.

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking
User=root

ExecStart=/opt/apache-tomcat-7.0.42/bin/jsvc \
-user tomcat \
-home /opt/jdk1.7.0_45 \
-Dcatalina.home=/opt/apache-tomcat-7.0.42 \
-Dcatalina.base=/opt/apache-tomcat-7.0.42 \
-Djava.io.tmpdir=/var/tmp \
-Djava.awt.headless=true \
-Xms512m \
-Xmx1024m \
-outfile /opt/apache-tomcat-7.0.42/logs/catalina.out \
-errfile /opt/apache-tomcat-7.0.42/logs/catalina.err \
-pidfile /var/run/tc7/jsvc.pid \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Djava.util.logging.config.file=/opt/apache-tomcat-7.0.42/conf/logging.properties
\
-cp 
/opt/apache-tomcat-7.0.42/bin/bootstrap.jar:/opt/apache-tomcat-7.0.42/bin/commons-daemon.jar:/opt/jdk1.7.0_45/lib/tools.jar:/opt/apache-tomcat-7.0.42/bin/tomcat-juli.jar
\
org.apache.catalina.startup.Bootstrap

ExecStop=/bin/kill -9 /var/run/tc7/jsvc.pid
ExecStopPost=/bin/rm -f /var/tc7lock/subsys/tomcat /var/run/tc7/jsvc.pid

[Install]
WantedBy=multi-user.target

This works fine and Tomcat starts as expected when the system reboots.

Hope this saves someone some aggravation. There is still much that is
not understood and experimentation is ongoing as time allows.

Lyallex

=========================== /etc/rc.d/init.d/tomcat7 ===========================
JAVA_HOME=/opt/jdk1.7.0_45
CATALINA_HOME=/opt/apache-tomcat-7.0.42
export JAVA_HOME CATALINA_HOME
CLASSPATH=$CATALINA_HOME/bin/bootstrap.jar:$CATALINA_HOME/bin/commons-daemon.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/bin/tomcat-juli.jar
TOMCAT_USER=tomcat
TMPDIR=/var/tmp
PIDFILE=/var/run/tc7/jsvc.pid


RC=0

case "$1" in

  start)

   $CATALINA_HOME/bin/jsvc -user $TOMCAT_USER -home $JAVA_HOME
-Dcatalina.home=/opt/apache-tomcat-7.0.42
-Dcatalina.base=$CATALINA_HOME -Djava.io.tmpdir=$TMPDIR
-Djava.awt.headless=true \
     -Xms512m \
     -Xmx1024m \
     -outfile $CATALINA_HOME/logs/catalina.out \
     -errfile $CATALINA_HOME/logs/catalina.err \
     -pidfile '/var/run/tc7/jsvc.pid' \
     -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
     -Djava.util.logging.config.file=$CATALINA_HOME/conf/logging.properties \
     -cp $CLASSPATH  \
     org.apache.catalina.startup.Bootstrap

    RC=$?

    [ $RC = 0 ] && touch /var/tc7lock/subsys/tomcat
    echo "starting tomcat7 on darkstar with:"
    echo "JAVA_HOME=$JAVA_HOME"
    echo "CATALINA_HOME=$CATALINA_HOME"
    echo "CLASSPATH=$CLASSPATH"
    echo "tomcat started"
    ;;

  stop)

    PID=`cat /var/run/tc7/jsvc.pid`
    kill $PID

   RC=$?

    [ $RC = 0 ] && rm -f /var/tc7lock/subsys/tomcat /var/run/tc7/jsvc.pid
    echo "stopping tomcat7 on darkstar with:"
    echo "JAVA_HOME=$JAVA_HOME"
    echo "CATALINA_HOME=$CATALINA_HOME"
    echo "CLASSPATH=$CLASSPATH"

    echo "tomcat stopped"
    ;;

  *)
        echo "Usage: $0 {start|stop}"
        exit 1
esac
exit $RC

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to