![systemd 服务启动脚本在 16.04 中有效,但在 18.04 中抛出错误](https://linux22.com/image/1007212/systemd%20%E6%9C%8D%E5%8A%A1%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC%E5%9C%A8%2016.04%20%E4%B8%AD%E6%9C%89%E6%95%88%EF%BC%8C%E4%BD%86%E5%9C%A8%2018.04%20%E4%B8%AD%E6%8A%9B%E5%87%BA%E9%94%99%E8%AF%AF.png)
我已将以下jenkins-agent.service
文件放置在/etc/systemd/system/
:
[Unit]
Description=Jenkins agent
Requires=network-online.target
After=network-online.target
[Service]
ExecStart=/usr/bin/java -jar /home/jenkins/jenkins/Agent/agent.jar -jnlpUrl http://my.jenkins.server.com:8087/jenkins/computer/Ubuntu%2064-bit/slave-agent.jnlp -secret d1ac22621ad4c460e5f8de4f564345fa7cdb2bea1d26b6f17230451a37a08e7e -workDir "/home/jenkins/jenkins"
Restart=always
[Install]
Wants=network-online.target
WantedBy=multi-user.target
它已注册systemd
并完美地在系统启动时启动 Jenkins 代理进程。但我刚刚更新到 18.04,现在此脚本抛出语法错误:
systemd-analyze verify /etc/systemd/system/jenkins-agent.service
File /lib/systemd/system/systemd-journald.service:36 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
/etc/systemd/system/jenkins-agent.service:7: Failed to resolve unit specifiers on http://my.jenkins.sever.com:8087/jenkins/computer/Ubuntu%2064-bit/slave-agent.jnlp: Invalid slot
jenkins-agent.service: Failed to create jenkins-agent.service/start: Unit jenkins-agent.service is not loaded properly: Exec format error.
Attempted to remove disk file system, and we can't allow that.
如何修复?我不明白哪里出了问题。它说问题出在该Unit
部分,所以我检查了该部分/lib/systemd/system/network-online.target
是否存在(确实存在)。
答案1
%
问题在于这里的使用:
.../Ubuntu%2064-bit/...
# ^
SystemD 使用%
作为各种内部格式说明符的关键字,并且ExecStart
这些格式说明符(及其兄弟)可用于动态替换值。由于它无法解释%2
为正确的说明符,因此您得到:
Exec format error
您需要使用%
另一个来逃脱%
:
.../Ubuntu%%2064-bit/...