Tomcat - As a systemd service

To use systemctl to start and stop a Tomcat, you need to do the following (particular for Tomcat 9)

1. Create a service file

I use sudo (as you need root access) and VI as text editor

sudo vi /etc/systemd/system/tomcat9.service

2. Add the following into tomcat9.service

[Unit]

Description=Tomcat9
After=syslog.target network.target

[Service]

Type=forking


User=tomcat
Group=tomcat

WorkingDirectory="/tomcat/tomcat9"

Environment="JAVA_HOME=/java/jdk-11-latest"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/tomcat/tomcat9"
Environment="CATALINA_HOME=/tomcat/tomcat9/"
Environment="CATALINA_PID=/tomcat/tomcat9//temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx4096M -server -XX:+UseParallelGC"

ExecStart=/tomcat/tomcat9/bin/startup.sh
ExecStop=/tomcat/tomcat9/bin/shutdown.sh

[Install]

WantedBy=multi-user.target

3. Reload the service

sudo systemctl daemon-reload
sudo systemctl enable tomcat

4. Start, Stop and check Status the server

sudo systemctl start tomcat9
sudo systemctl stop tomcat9
sudo systemctl status tomcat9

Comments

Popular Posts