Skip to content

Instantly share code, notes, and snippets.

@zengxs
Last active August 14, 2022 17:26
Show Gist options
  • Save zengxs/a697d786b244d7b857d3d006213306a1 to your computer and use it in GitHub Desktop.
Save zengxs/a697d786b244d7b857d3d006213306a1 to your computer and use it in GitHub Desktop.
tomcat systemd service script
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINE_BASE=/opt/tomcat
Environment='CATALINE_OPTS=-Xms128M -Xmx765M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.haedless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target
@yateam
Copy link

yateam commented Dec 20, 2018

@lvarela
Copy link

lvarela commented Jan 8, 2019

Only way to make tomcat 9.0.14 work with systemd units on Centos 7.6 was with oers example.
Here is what I use (with custom OPTS):

[Unit]
Description=Tomcat
After=network.target

[Service]
User=tomcat
WorkingDirectory=/opt/tomcat
Environment=JRE_HOME=/usr/lib/jvm/jre
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINE_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Dfile.encoding=ISO-8859-1'
Environment='JAVA_OPTS=-server -Xms512M -Xmx1G -Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom  -XX:+UseConcMarkSweepGC -Djava.net.preferIPv4Stack=true -Dsun.net.inetaddr.ttl=0'
ExecStart=/opt/tomcat/bin/catalina.sh run
ExecStop=/opt/tomcat/bin/shutdown.sh
SyslogIdentifier=tomcat-%i

[Install]
WantedBy=multi-user.target

@mr-rycho
Copy link

mr-rycho commented Apr 2, 2019

Type=forking -> catalina.sh start or startup.sh
Type=simple (default?) -> catalina.sh run

@richardsonlima
Copy link

@mr-rycho In the Type=simple model, the process spawned by systemd is the dæmon

@ogronome
Copy link

catalinE ?! CATALINUS is much better )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment