首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ExecStart有一个“-”前缀,但该单元仍然失败

ExecStart有一个“-”前缀,但该单元仍然失败
EN

Server Fault用户
提问于 2022-07-04 08:54:29
回答 1查看 331关注 0票数 1

我已经重写了dnf-makecache,不让我的系统每次在互联网上出现问题时都处于失败状态(令人震惊!)但它似乎被忽视了。

代码语言:javascript
运行
复制
# sc cat dnf-makecache.service
# /usr/lib/systemd/system/dnf-makecache.service
[Unit]
Description=dnf makecache
# On systems managed by either rpm-ostree/ostree, dnf is read-only;
# while someone might theoretically want the cache updated, in practice
# anyone who wants that could override this via a file in /etc.
ConditionPathExists=!/run/ostree-booted

After=network-online.target

[Service]
Type=oneshot
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
Environment="ABRT_IGNORE_PYTHON=1"
ExecStart=/usr/bin/dnf makecache --timer

# /etc/systemd/system/dnf-makecache.service.d/override.conf
[Service]
ExecStart=-/usr/bin/dnf makecache --timer
[root@lxd10 ~]# man systemd.service
[root@lxd10 ~]# sc cat dnf-makecache
# /usr/lib/systemd/system/dnf-makecache.service
[Unit]
Description=dnf makecache
# On systems managed by either rpm-ostree/ostree, dnf is read-only;
# while someone might theoretically want the cache updated, in practice
# anyone who wants that could override this via a file in /etc.
ConditionPathExists=!/run/ostree-booted

After=network-online.target

[Service]
Type=oneshot
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
Environment="ABRT_IGNORE_PYTHON=1"
ExecStart=/usr/bin/dnf makecache --timer

# /etc/systemd/system/dnf-makecache.service.d/override.conf
[Service]
ExecStart=-/usr/bin/dnf makecache --timer

但是它仍然失败,系统状态被降级。

代码语言:javascript
运行
复制
Jun 28 09:08:35 lxd10.2e-systems.com systemd[1]: dnf-makecache.service: Main process exited, code=exited, status=1/FAILURE
Jun 28 09:08:35 lxd10.2e-systems.com systemd[1]: dnf-makecache.service: Failed with result 'exit-code'.
Jun 28 09:08:35 lxd10.2e-systems.com systemd[1]: Failed to start dnf makecache.

但手册明确表示,如果执行路径以破折号作为前缀,则退出代码将被忽略。我做错了什么?也许是因为它是由计时器运行的?

EN

回答 1

Server Fault用户

回答已采纳

发布于 2022-07-04 09:46:53

来自systemd.service(5)

除非Type=oneshot,否则必须给出一个命令。当使用Type=oneshot时,可以指定零条或多条命令。可以通过在同一指令中提供多个命令行来指定命令,或者可以以相同的效果多次指定此指令。如果将空字符串分配给此选项,则将重新设置要启动的命令列表,此选项的先前分配将没有任何效果。 ...

同样,来自systemd.unit(5)

请注意,对于插入文件,如果要从解析为列表(而不是依赖项)的设置中删除条目,例如AssertPathExists= (或服务单元中的ExecStart= ),则需要先清除列表,然后再添加除要删除的条目以外的所有条目。 ...

因此,对于当前OP的override.conf文件(因为类型是oneshot ),ExecStart=现在是一个两个元素列表:/usr/bin/dnf makecache --timer-/usr/bin/dnf makecache --timer。然后,应用于:

如果指定了多个命令,则按它们在单元文件中出现的顺序顺序调用这些命令。如果其中一个命令失败(并且没有以“-”作为前缀),则不会执行其他行,并且该单元被认为失败。

由于没有-的原始命令仍然被执行,当它失败时,服务就会失败。

要替换它,override.conf文件应该包括如下内容:

代码语言:javascript
运行
复制
[Service]
ExecStart=
ExecStart=-/usr/bin/dnf makecache --timer
票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1104738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档