【问题标题】:systemd failing to start custom made service for Tomcatsystemd 无法为 Tomcat 启动定制服务
【发布时间】:2015-10-24 11:56:01
【问题描述】:

我正在获得我创建的一个简单的 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!

所以我有点困惑。我试图从路径中删除\s,认为它可能利用了一些奇怪的受 Windows 影响的风格。仍然没有任何效果。

我哪里搞砸了?

【问题讨论】:

  • ...搞砸了?当时您决定在文件夹名称中使用空格 ;-)
  • @Marged So.. systemd 没有正确处理空格的能力?这似乎.. 很不一样.. 考虑到有多少发行版全心全意地采用它。
  • 除了检查所有涉及删除空格的文件夹的权限之外,这是我第一次尝试解决这个问题

标签: linux tomcat systemd


【解决方案1】:

事实证明,在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 现在不再有路径或查找指定二进制文件的问题。

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 2020-05-11
    • 2019-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    相关资源
    最近更新 更多