systemd 单元中的 Requires= 未按预期工作,两个单元同时启动

systemd 单元中的 Requires= 未按预期工作,两个单元同时启动

我试图强制一个单元在另一个单元启动之前运行完成,并且所有文档都说我应该信任 Requires=,但它并没有像广告中说的那样工作。

这是我正在启动的实际单元(它是由四元组生成的)。

# Automatically generated by /usr/lib/systemd/system-generators/podman-system-generator
# 
[Unit]
Description=Traefik
Wants=network-online.target
After=network-online.target
[email protected]
SourcePath=/etc/containers/systemd/traefik.container
RequiresMountsFor=%t/containers
RequiresMountsFor=/var/opt/traefik/traefik.toml
RequiresMountsFor=/var/opt/traefik/dynamic.toml
Requires=acme-volume.service
After=acme-volume.service

[X-Container]
ContainerName=traefik
Image=docker.io/traefik:v2.10
Volume=/var/opt/traefik/traefik.toml:/var/opt/traefik/traefik.toml:Z
Volume=/var/opt/traefik/dynamic.toml:/var/opt/traefik/dynamic.toml:Z
Volume=acme.volume:/var/opt/traefik/letsencrypt/:Z
PublishPort=80:80
PublishPort=443:443
EnvironmentFile=/var/opt/traefik/environment
Exec=--configFile=/var/opt/traefik/traefik.toml

[Service]
Restart=always
Environment=PODMAN_SYSTEMD_UNIT=%n
KillMode=mixed
ExecStop=/usr/bin/podman rm -f -i --cidfile=%t/%N.cid
ExecStopPost=-/usr/bin/podman rm -f -i --cidfile=%t/%N.cid
Delegate=yes
Type=notify
NotifyAccess=all
SyslogIdentifier=%N
ExecStart=/usr/bin/podman run --name=traefik --cidfile=%t/%N.cid --replace --rm --cgroups=split --sdnotify=conmon -d -v /var/opt/traefik/traefik.toml:/var/opt/traefik/traefik.toml:Z -v /var/opt/traefik/dynamic.toml:/var/opt/traefik/dynamic.toml:Z -v systemd-acme:/var/opt/traefik/letsencrypt/:Z --publish 80:80 --publish 443:443 --env-file /var/opt/traefik/environment docker.io/traefik:v2.10 --configFile=/var/opt/traefik/traefik.toml

[Install]
WantedBy=multi-user.target default.target

请注意,它有这条线[email protected]

这就是那个单位。/etc/systemd/system/[email protected]

[Unit]
Description=podman volume import %i
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
EnvironmentFile=/etc/podman-volume-backup/environment
ExecStart=/usr/local/bin/podman-volume-restore.bash %i
Restart=on-failure
KillMode=process
TimeoutStopSec=300

当我运行systemctl start traefik并检查两个单元的日志时,我发现 traefik 与 podman-volume-restore 同时启动。它根本没有像文档中说的那样等待它退出。

我的依赖项有什么问题?

答案1

我说得太早了。我错过了只有当您还指定 After= 时 Requires 才会按顺序工作。

因此现在将 After 行更改为后,它可以按预期工作。After=network-online.target [email protected]

相关内容