2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CentOS8でTomcat8の自動起動設定で2度ハマった話

Last updated at Posted at 2020-08-11

#概要
掲題の件で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.

#うまくいく場合

https://stackoverflow.com/questions/53994521/tomcat-8-on-centos-7-does-not-start-as-service-but-it-starts-manually を参考にするとよい。

最終的にうまくいった設定。上の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
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?