enable tomcat9 as systemd service

Hi,

I have installed tomcat9 in /opt/tomcat9 folder .
after execute /opt/tomcat9/bin/startup.sh , I able to access the tomcat mainpage, manager /host-manager page . but when i try to enable it as systemd service I get error when i try to access the mainpage

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

type Exception report

message java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

description The server encountered an internal error that prevented it from fulfilling this request.

exception
////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here a simple script for tomcat9.service

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

[Service]
Type=forking
ExecStart=/opt/tomcat9/bin/startup.sh
ExecStop=/opt/tomcat9/bin/shutdown.sh
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.targer

////////////////////////////////////////////////////////////////////////////////////////////////////////
return by systemctl status after I execute systemctl start tomcat9.service

Warning: tomcat9.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
bt01:/usr/lib/systemd/system # systemctl status tomcat9.service -l
● tomcat9.service - Apache Tomcat Web Application Container
Loaded: loaded (/usr/lib/systemd/system/tomcat9.service; disabled; vendor preset: disabled)
Active: active (running) since Fri 2016-05-06 17:44:19 SGT; 3s ago
Process: 2625 ExecStop=/opt/tomcat9/bin/shutdown.sh (code=exited, status=0/SUCCESS)
Process: 2786 ExecStart=/opt/tomcat9/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 2802 (java)
Tasks: 23 (limit: 512)
CGroup: /system.slice/tomcat9.service
└─2802 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat9/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -classpath /opt/tomcat9/bin/bootstrap.jar:/opt/tomcat9/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat9 -Dcatalina.home=/opt/tomcat9 -Djava.io.tmpdir=/opt/tomcat9/temp org.apache.catalina.startup.Bootstrap start

May 06 17:44:19 bt01 systemd[1]: Starting Apache Tomcat Web Application Container…
May 06 17:44:19 bt01 startup.sh[2786]: Tomcat started.
May 06 17:44:19 bt01 systemd[1]: Started Apache Tomcat Web Application Container.
Warning: tomcat9.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.

am I missing something ?

Although I don’t personally run Tomcat today (and haven’t for many years)

Tomcat is a jsp container architecture running on Apache.

I’m guessing your Apache Server isn’t yet running.

I don’t know how this is intended to run on today’s openSUSE for sure, but I’d guess that you only need to start your Apache web server and Tomcat should automatically be available.

Am not sure why there would be a Tomcat service…Speculating a bit but based on historical architecture, I’d guess it should simply be a loadable service but <not> enabled because it really isn’t a true standalone service but is simply implemented on top of Apache.

TSU

Warning: tomcat9.service changed on disk. Run 'systemctl daemon-reload' to reload units.

Did you do the following yet?

systemctl daemon-reload

Also, I note

Loaded: loaded (/usr/lib/systemd/system/tomcat9.service; disabled; vendor preset: disabled)

To enable it permanently (for subsequent boots), do this first

systemctl enable tomcat9

Be careful with typos. You have

[Install]
WantedBy=multi-user.targer

It should be

[Install]
WantedBy=multi-user.target

BTW, there isn’t a syslog.target with openSUSE, so although it won’t hurt to have it included, it isn’t relevant/necessary to have it listed explicitly. Amend it like this

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

Info:
https://lists.opensuse.org/opensuse-packaging/2013-05/msg00102.html

After try and error . this script work. I can upload Birt report war and run the report.
but I still don’t know if this script is correct.

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

[Service]
User=tomcat
Group=tomcat
Environment=CATALINA_BASE=/opt/tomcat9
Environment=CATALINA_HOME=/opt/tomcat9
Environment=JRE_HOME=/usr/lib64/jvm/jre
Environment=CATALINA_TMPDIR=/opt/tomcat9/temp
Environment= CLASSPATH=/opt/tomcat9/bin/bootstrap.jar:/opt/tomcat9/bin/tomcat-juli.jar
Environment=‘CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC’
Environment=‘JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom’

ExecStart=/opt/tomcat9/bin/catalina.sh run
ExecStop=/opt/tomcat9/bin/catalina.sh stop

[Install]
WantedBy=multi-user.target