[Java] Talk that I got hooked twice with automatic startup setting of Tomcat 8 with CentOS 8

1 minute read

Overview

I solved the problem once in the subject matter, but I encountered the same problem again in another environment, and since I was not keeping a record, I struggled for 2 hours and made a note not to repeat the third mistake in the future.

environment

  • CentOS8.2
  • OpenJDK8
  • Tomcat8.0

If something goes wrong

If you create /etc/systemd/system/tomcat.service as the example in (https://weblabo.oscasierra.net/installing-tomcat8-centos7-1/), it will not work.

File Edit Options Buffers Tools Help
[Unit]
Description=Apache Tomcat 8
After=network.target

[Service]
User=tomcat
Group=tomcat
Type=oneshot
PIDFile=/usr/java/tomcat8/temp/tomcat.pid
RemainAfterExit=yes

ExecStart=/usr/java/tomcat8/bin/startup.sh
ExecStop=/usr/java/tomcat8/bin/shutdown.sh
ExecReStart=/usr/java/tomcat8/bin/shutdown.sh;/usr/java/tomcat8/bin/startup.sh

[Install]
WantedBy=multi-user.target

Error if something goes wrong

By the way, if /usr/java/tomcat8/bin/startup.sh is executed manually, it works without problems.

[[email protected] ~]# systemctl start tomcat
Job for tomcat.service failed because the control process exited with error code.
See "systemctl status tomcat.service" and "journalctl -xe" for details.

August 11 23:47:39 localhost.localdomain systemd[1]: Starting Apache Tomcat 8...
- -Subject: Unit tomcat.service has begun start-up
- -Defined-By: systemd
- -Support: https://access.redhat.com/support
- 
- -Unit tomcat.service has begun starting up.
 Aug 11 23:47:39 localhost.localdomain systemd[2079]: tomcat.service: Failed to execute command: Permission denied
 August 11 23:47:39 localhost.localdomain systemd[2079]: tomcat.service: Failed at step EXEC spawning /usr/java/tomcat8/bin/startup.sh: Permission denied
- -Subject: Process /usr/java/tomcat8/bin/startup.sh could not be executed
- -Defined-By: systemd
- -Support: https://access.redhat.com/support
- 
- -The process /usr/java/tomcat8/bin/startup.sh could not be executed and failed.
- 
- -The error number returned by this process is 13.
 August 11 23:47:39 localhost.localdomain systemd[1]: tomcat.service: Main process exited, code=exited, status=203/EXEC
 Aug 11 23:47:39 localhost.localdomain systemd[1]: tomcat.service: Failed with result'exit-code'.
 Aug 11 23:47:39 localhost.localdomain systemd[1]: Failed to start Apache Tomcat 8.
- -Subject: Unit tomcat.service has failed
- -Defined-By: systemd
- -Support: https://access.redhat.com/support
- 
- -Unit tomcat.service has failed.
- 
- -The result is failed.

If it works

Refer to https://stackoverflow.com/questions/53994521/tomcat-8-on-centos-7-does-not-start-as-service-but-it-starts-manually.

The setting that finally worked. As mentioned in the URL above, is Working Directory questionable after all?

/etc/systemd/system/tomcat.service


[Unit]
Description=Apache Tomcat 8
After=network.target

[Service]
Type=forking
WorkingDirectory=/usr/java/tomcat8/bin

ExecStart=/bin/bash /usr/java/tomcat8/bin/catalina.sh start
ExecStop=/bin/bash /usr/java/tomcat8/bin/catalina.sh stop

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target