systemd 服务启动脚本在 16.04 中有效,但在 18.04 中抛出错误

systemd 服务启动脚本在 16.04 中有效,但在 18.04 中抛出错误

我已将以下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/...

相关内容