1

Starting with version 8.0, Red Hat Enterprise Linux (RHEL) no longer provides any version of the Apache Tomcat JAVA webserver/servlet as part of the RHEL distribution.[1]

Therefore, we have to install Tomcat via WAR file in the RHEL systems. The problem which arises is that it becomes difficult to start, stop or restart the Tomcat service as there is to service file installed, through which we could have easily used the command service tomcat start to start the service.

But there is a way through which we can create this service manually by writing a Systemd script. By placing this script in the /etc/systemd/system/ directory, we can use the service commands for managing the Tomcat Service.

Please share the Tomcat Service Creation Script.

Avik
  • 371
  • 4
  • 15

1 Answers1

1

This the Service Creation File. Copy and paste this file in the /etc/systemd/system/ directory.

The name of the file should be tomcat.service

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

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-0.el8_2.x86_64/jre

Environment=CATALINA_PID={{ tomcat_dir }}/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME={{ tomcat_dir }}/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true'
Environment='JAVA_OPTS=-Djava.awt.headless=true'

ExecStart={{ tomcat_dir }}/tomcat/bin/startup.sh
ExecStop={{ tomcat_dir }}/tomcat/bin/shutdown.sh
SuccessExitStatus=143

RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Now you can easily manage the Tomcat Service with the Systemd Commands, even in RHEL8.

Avik
  • 371
  • 4
  • 15
  • This does not work for me. Starting the service with systemd does not work. journalctl -xe says `permission denied` for `ExecStart=.../bin/startup.sh` – theerrormagnet Jul 19 '22 at 10:12
  • 1
    You have to add the user inside the Service section, if we consider a user like appUser:appGroup you have to add: User=appUser . You can also add the group: Group=appGroup. – Piergiorgio Lucidi Jul 27 '22 at 06:50