systemd 无法为 Tomcat 启动定制服务
systemd failing to start custom made service for Tomcat
我正在获取我创建的用于正确启动的简单 systemd 服务。
这里是 tomcat.service,我已将其放入 /lib/systemd/system
:
[Unit]
Description=A systemd daemon configured to run Apache Tomcat 8.
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/tomcat.pid
ExecStart=/home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/startup.sh
ExecStop=/home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
将文件放入文件夹后,我有 运行 systemctl enable tomcat.service
.
在此之后,运行ning sudo systemctl start tomcat.service
给我以下错误:
Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.
通过 sudo journalctl
仔细检查有问题的错误会发现以下相关错误:
Oct 24 19:22:05 theforge systemd[6674]: Failed at step EXEC spawning /home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/startup.sh: No such file or directory
Oct 24 19:22:05 theforge systemd[1]: tomcat.service: control process exited, code=exited status=203
但是,我知道给 ExecStart
的位置确实存在,因为我可以将这个非常花絮粘贴到我的 shell 中,它会完美地启动 Tomcat!
所以我有点纳闷。我试图从路径中删除 \
s,认为它可能使用了一些奇怪的 Windows-influenced 样式。仍然没有任何效果。
我哪里搞砸了?
事实证明,在 unit
文件中使用带空格的路径的唯一方法是删除转义字符并双引号整个路径。
[Service]
Type=forking
PIDFile="/home/technomage/Migration/Programming Files/Development Plugins and Software/apache-tomcat-8.0.26/bin/tomcat.pid"
ExecStart="/home/technomage/Migration/Programming Files/Development Plugins and Software/apache-tomcat-8.0.26/bin/startup.sh"
ExecStop="/home/technomage/Migration/Programming Files/Development Plugins and Software/apache-tomcat-8.0.26/bin/shutdown.sh"
这似乎是一个显而易见的解决方案,除了这里的问题是 "feature" 仅在较新版本的 systemd
中受支持。
Debian Jessie(我正在使用的发行版)附带的 systemd
结果没有该功能。所以唯一的办法就是升级到最新版本。
Debian Jessie 开箱即用,版本非常旧,215-17
。
我通过暂时将存储库更改为 sid
、更新源并升级 systemd
.
解决了这个问题
有了这个,systemd
现在路径或找到所述二进制文件不再有问题。
我正在获取我创建的用于正确启动的简单 systemd 服务。
这里是 tomcat.service,我已将其放入 /lib/systemd/system
:
[Unit]
Description=A systemd daemon configured to run Apache Tomcat 8.
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/tomcat.pid
ExecStart=/home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/startup.sh
ExecStop=/home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
将文件放入文件夹后,我有 运行 systemctl enable tomcat.service
.
在此之后,运行ning sudo systemctl start tomcat.service
给我以下错误:
Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.
通过 sudo journalctl
仔细检查有问题的错误会发现以下相关错误:
Oct 24 19:22:05 theforge systemd[6674]: Failed at step EXEC spawning /home/technomage/Migration/Programming\ Files/Development\ Plugins\ and\ Software/apache-tomcat-8.0.26/bin/startup.sh: No such file or directory
Oct 24 19:22:05 theforge systemd[1]: tomcat.service: control process exited, code=exited status=203
但是,我知道给 ExecStart
的位置确实存在,因为我可以将这个非常花絮粘贴到我的 shell 中,它会完美地启动 Tomcat!
所以我有点纳闷。我试图从路径中删除 \
s,认为它可能使用了一些奇怪的 Windows-influenced 样式。仍然没有任何效果。
我哪里搞砸了?
事实证明,在 unit
文件中使用带空格的路径的唯一方法是删除转义字符并双引号整个路径。
[Service]
Type=forking
PIDFile="/home/technomage/Migration/Programming Files/Development Plugins and Software/apache-tomcat-8.0.26/bin/tomcat.pid"
ExecStart="/home/technomage/Migration/Programming Files/Development Plugins and Software/apache-tomcat-8.0.26/bin/startup.sh"
ExecStop="/home/technomage/Migration/Programming Files/Development Plugins and Software/apache-tomcat-8.0.26/bin/shutdown.sh"
这似乎是一个显而易见的解决方案,除了这里的问题是 "feature" 仅在较新版本的 systemd
中受支持。
Debian Jessie(我正在使用的发行版)附带的 systemd
结果没有该功能。所以唯一的办法就是升级到最新版本。
Debian Jessie 开箱即用,版本非常旧,215-17
。
我通过暂时将存储库更改为 sid
、更新源并升级 systemd
.
有了这个,systemd
现在路径或找到所述二进制文件不再有问题。