I solved the problem once, but I encountered the same problem again in another environment and did not keep a record, so I struggled for 2 hours and made a note not to repeat the third mistake in the future.
If I create /etc/systemd/system/tomcat.service as in the example at (https://weblabo.oscasierra.net/installing-tomcat8-centos7-1/), it doesn't 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
By the way, if you run /usr/java/tomcat8/bin/startup.sh manually, it works fine.
[root@localhost ~]# 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.
August 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
August 11 23:47:39 localhost.localdomain systemd[1]: tomcat.service: Failed with result 'exit-code'.
August 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.
You may want to 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 the Working Directory suspicious 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
Recommended Posts