我正在获取我创建的一个简单的 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
。
在此之后,运行 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!
所以我有点迷茫。我试图从路径中删除 \
,认为它可能使用了一些奇怪的受 Windows 影响的样式。仍然没有任何效果。
我哪里搞砸了?
最佳答案
事实证明,在 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"
这似乎是一个显而易见的解决方案,除了这里的问题是此“功能”仅在较新版本的 systemd
中受支持。
Debian Jessie(我正在使用的发行版)附带的 systemd
结果没有该功能。所以唯一的办法就是升级到最新版本。
Debian Jessie 开箱即用了一个非常旧的版本,215-17
。
我通过暂时将我的存储库更改为 sid
、更新我的源并升级 systemd
解决了这个问题。
有了这个,systemd
现在不再有路径问题或找到指定的二进制文件。
关于linux - systemd 无法为 Tomcat 启动定制服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33317901/