Centos

如何修復我的 systemctl 狀態 tomcat?

  • August 12, 2019

我怎樣才能systemctl status tomcat返回“成功”而不是“失敗”?

這是我的 etc/systemd/system/tomcat.service 文件:

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

[Service]
Type=forking

Environment=JRE_HOME=JAVA_HOME='/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/'
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
#Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

現在,當我檢查我的 tomcat 的狀態時,它說

# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
  Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Sat 2019-08-10 14:03:10 EDT; 55min ago
Main PID: 22165 (code=exited, status=127)

Aug 10 14:03:10 localhost.localdomain kill[22167]: -q, --queue <sig>      use sigqueue(2) rather than kill(2)
Aug 10 14:03:10 localhost.localdomain kill[22167]: -p, --pid              print pids without signaling them
Aug 10 14:03:10 localhost.localdomain kill[22167]: -l, --list [=<signal>] list signal names, or convert one to a name
Aug 10 14:03:10 localhost.localdomain kill[22167]: -L, --table            list signal names and numbers
Aug 10 14:03:10 localhost.localdomain kill[22167]: -h, --help     display this help and exit
Aug 10 14:03:10 localhost.localdomain kill[22167]: -V, --version  output version information and exit
Aug 10 14:03:10 localhost.localdomain kill[22167]: For more details see kill(1).
Aug 10 14:03:10 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Aug 10 14:03:10 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.
Aug 10 14:03:10 localhost.localdomain systemd[1]: tomcat.service failed.



Caused by: java.net.ConnectException: Connection refused (Connection refused)

我在嘗試執行 sudo certbot –apache 時遇到此錯誤

Error while running apachectl graceful.

Job for httpd.service invalid.

Unable to restart apache using ['apachectl', 'graceful']
Error while running apachectl restart.

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

Encountered exception during recovery: 
Traceback (most recent call last):
 File "/usr/lib/python2.7/site-packages/certbot/error_handler.py", line 124, in _call_registered
   self.funcs[-1]()
 File "/usr/lib/python2.7/site-packages/certbot/auth_handler.py", line 220, in _cleanup_challenges
   self.auth.cleanup(achalls)
 File "/usr/lib/python2.7/site-packages/certbot_apache/configurator.py", line 2332, in cleanup
   self.restart()
 File "/usr/lib/python2.7/site-packages/certbot_apache/configurator.py", line 2202, in restart
   self._reload()
 File "/usr/lib/python2.7/site-packages/certbot_apache/configurator.py", line 2229, in _reload
   raise errors.MisconfigurationError(error)
MisconfigurationError: Error while running apachectl restart.

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

這是我的 journalctl -xe: https ://pastebin.com/JvJ8Uej0 這是我的 journalctl -b -u tomcat: https ://pastebin.com/zPqEBGXH

嘗試殺死程序但沒有工作:

# kill 23656
bash: kill: (23656) - No such process

在此處輸入圖像描述 這可能是什麼原因?如何修復這些錯誤?該網站執行良好,但我收到了這些錯誤。

我的問題是單元文件中的行:

Environment=JRE_HOME=JAVA_HOME='/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/'

它應該沒有引號:

Environment=JRE_HOME=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/

我可以通過嘗試systemctl restat tomcat然後查看日誌來找到這個catalia.out錯誤,/opt/tomcat/bin/catalina.sh其中的/opt/tomcat/bin/startup.sh呼叫看起來像是 JAVA_HOME 的錯誤。

感謝 djdomi 在評論中幫助我到達那裡。

引用自:https://serverfault.com/questions/978731