#概要
掲題の件で1度解決したが、再度別の環境で同じ問題に遭遇し、記録をとっていなかったがために、2時間格闘してしまい、今後3度目の過ちを繰り返さないようメモ。
#環境
- CentOS8.2
- OpenJDK8
- Tomcat8.0
#うまくいかない場合
(https://weblabo.oscasierra.net/installing-tomcat8-centos7-1/) にある例の通りに/etc/systemd/system/tomcat.serviceを作成した場合、うまくいかない。
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
#うまくいかない場合に出るエラー
ちなみに/usr/java/tomcat8/bin/startup.sh を手動で実行すると問題なく動作する。
[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.
8月 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.
8月 11 23:47:39 localhost.localdomain systemd[2079]: tomcat.service: Failed to execute command: Permission denied
8月 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.
8月 11 23:47:39 localhost.localdomain systemd[1]: tomcat.service: Main process exited, code=exited, status=203/EXEC
8月 11 23:47:39 localhost.localdomain systemd[1]: tomcat.service: Failed with result 'exit-code'.
8月 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.
#うまくいく場合
最終的にうまくいった設定。上のURLにも記載されているが、結局WorkingDirectoryが怪しい?
/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