我已经在 Ubuntu 18.04 上安装了 Tomcat 9,并尝试将其添加到服务中。
但是,与其他用户不同,tomcat.pid
文件在任何地方都不存在。所以我的 Tomcat 服务文件会产生错误。
[Unit]
Description=Apache Tomcat 9 Servlet Container
After=syslog.target network.target
[Service]
User=nblizz
Group=nblizz
Type=forking
Environment=CATALINA_PID=/opt/apache-tomcat-9.0.16/tomcat.pid <--- !! (Not exist)
Environment=CATALINA_HOME=/opt/apache-tomcat-9.0.16
Environment=CATALINA_BASE=/opt/apache-tomcat-9.0.16
ExecStart=/opt/apache-tomcat-9.0.16/bin/startup.sh
ExecStop=/opt/apache-tomcat-9.0.16/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
运行Tomcat没问题,但是停止tomcat的时候报错。
● apache-tomcat.service - Apache Tomcat 9 Servlet Container
Loaded: loaded (/etc/systemd/system/apache-tomcat.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2019-03-16 01:30:39 KST; 1s ago
Process: 1462 ExecStop=/opt/apache-tomcat-9.0.16/bin/shutdown.sh (code=exited, status=1/FAILURE) <--- !!
Process: 545 ExecStart=/opt/apache-tomcat-9.0.16/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 573 (code=killed, signal=TERM)
Mar 16 01:17:29 ndelt-personal systemd[1]: Starting Apache Tomcat 9 Servlet Container...
Mar 16 01:17:29 ndelt-personal startup.sh[545]: Tomcat started.
Mar 16 01:17:29 ndelt-personal systemd[1]: Started Apache Tomcat 9 Servlet Container.
Mar 16 01:30:39 ndelt-personal systemd[1]: Stopping Apache Tomcat 9 Servlet Container...
Mar 16 01:30:39 ndelt-personal shutdown.sh[1462]: $CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted.
Mar 16 01:30:39 ndelt-personal systemd[1]: apache-tomcat.service: Control process exited, code=exited status=1
Mar 16 01:30:39 ndelt-personal systemd[1]: apache-tomcat.service: Failed with result 'exit-code'.
Mar 16 01:30:39 ndelt-personal systemd[1]: Stopped Apache Tomcat 9 Servlet Container.
另外,文件的颜色与apache-tomcat.service
其他文件不同。(https://isstatic.askoverflow.dev/WnD3Y.png)
问题是什么?
看起来 catalina.sh 文件中的 v9.0.14 发生了变化
479c479
489c489
如果您在此处删除多余的 & 符号,则会按预期创建 pid 文件。