我已经重写了dnf-makecache,不让我的系统每次在互联网上出现问题时都处于失败状态(令人震惊!)但它似乎被忽视了。
# 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
但是它仍然失败,系统状态被降级。
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.
但手册明确表示,如果执行路径以破折号作为前缀,则退出代码将被忽略。我做错了什么?也许是因为它是由计时器运行的?
发布于 2022-07-04 09:46:53
除非
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
文件应该包括如下内容:
[Service]
ExecStart=
ExecStart=-/usr/bin/dnf makecache --timer
https://serverfault.com/questions/1104738
复制相似问题