gpt4 book ai didi

tomcat - systemctl 启动后停止tomcat

转载 作者:行者123 更新时间:2023-11-28 22:15:51 27 4
gpt4 key购买 nike

我正在尝试使用 systemctl 配置 Tomcat 8.5.37 以在 Ubuntu 16.04 上将服务器作为守护进程启动。

为此,我在/etc/systemd/system/tomcat8.service 中创建了以下服务文件:

[Unit]
Description=Tomcat Server
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/opt/jdk1.8
Environment=CATALINA_PID=/opt/tomcat8/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat8
Environment=CATALINA_BASE=/opt/tomcat8
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -Dlog4j.configurationFile=/opt/conf/log4j2.xml'
Environment='JAVA_OPTS=-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat8/bin/startup.sh
ExecStop=/opt/tomcat8/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007

#RestartSec=40
#Restart=always

[Install]
WantedBy=multi-user.target

Tomcat服务器直接从apache下载,只解压。JDK 是最新的 Oracle JDK 1.8。

当我直接通过 startup.sh 启动 tomcat 时一切正常。但是当我使用 systemctl 时(之前已经完成了 daemon-reload),它直接崩溃了。

systemctl status tomcat8 的输出:

● tomcat8.service - Tomcat Server
Loaded: loaded (/etc/systemd/system/tomcat8.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2019-01-04 23:14:08 CET; 2s ago
Process: 9793 ExecStop=/opt/tomcat8/bin/shutdown.sh (code=exited, status=0/SUCCESS)
Process: 9781 ExecStart=/opt/tomcat8/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 9791 (code=exited, status=0/SUCCESS)

journalctl -xe 的输出:

Jan 04 23:14:04 myserver.com systemd[1]: Starting Tomcat Server...
-- Subject: Unit tomcat8.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat8.service has begun starting up.
Jan 04 23:14:04 myserver.com startup.sh[9781]: Tomcat started.
Jan 04 23:14:04 myserver.com systemd[1]: Started Tomcat Server.
-- Subject: Unit tomcat8.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat8.service has finished starting up.
--
-- The start-up result is done.
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: Jan 04, 2019 11:14:06 PM org.apache.catalina.startup.Catalina stopServer
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: SEVERE: Could not contact [localhost:[8005]]. Tomcat may not be running.
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: Jan 04, 2019 11:14:07 PM org.apache.catalina.startup.Catalina stopServer
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: SEVERE: Catalina.stop:
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: java.net.ConnectException: Connection refused (Connection refused)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.PlainSocketImpl.socketConnect(Native Method)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.Socket.connect(Socket.java:589)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.Socket.connect(Socket.java:538)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.Socket.<init>(Socket.java:434)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.net.Socket.<init>(Socket.java:211)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:503)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at java.lang.reflect.Method.invoke(Method.java:498)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:406)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:498)
Jan 04 23:14:07 myserver.com shutdown.sh[9793]: The stop command failed. Attempting to signal the process to stop through OS signal.

异常不是问题,因为它试图关闭不再存在的服务。

我能看到的是,将创建日志文件,这让我明白了,启动过程已经开始。但是我对状态输出的过程感到困惑。有启动过程,有停止过程。

看起来startup.sh开始运行了,但是exit-code错误或者无法识别,systemd在startup.sh执行完后直接运行了ExecStop命令。

另一台服务器在该配置下运行良好,但在这里我直到现在都没有机会让它运行。

有人知道这种情况下的问题是什么吗?

谢谢!

最佳答案

这里的正确答案是“更新 Tomcat”,因为这是由启动脚本中的错误引起的,如 https://stackoverflow.com/a/54452870/4735682 中所述。

关于tomcat - systemctl 启动后停止tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54046940/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com