【问题标题】:systemd unit that's needed by multiple targets and stops when target stops多个目标需要并在目标停止时停止的 systemd 单元
【发布时间】:2021-07-15 14:10:22
【问题描述】:

我有一组单元需要与 multi-user.target 之后的多个目标一起运行。

例子:

multi-user.target example1.target example2.target multi-use.target

示例目标:

[Unit]
Description=Example target
Wants=multi-user.target
Requires=example.service
#PropagatesStopTo=example.service
Conflicts=rescue.service rescue.target
After=multi-user.target basic.target rescue.service rescue.target

服务单位示例:

[Unit]
Description=Example unit
After=multi-user.target
Wants=multi-user.target

[Service]
Environment=Some Enviroment
ExecStart=Some Binary
Restart=on-failure
RestartSec=1
Type=simple

[Install]
WantedBy=example1.target example2.target

主要问题是当我尝试停止当前正在运行的目标时,所有必需的单元都不会停止。 我尝试在目标中使用 PropagatesStopTo=example.service 没有成功。下面是输出: /lib/systemd/system/example1.target:7:“单元”部分中的未知键名“PropagatesStopTo”,忽略。 我的系统版本是: 系统 241 (241-166-g511646b+) 我知道我的 systemd 不支持 PropagatesStopTo,所以我正在尝试在我当前的 systemd 版本中找到替代方案。

【问题讨论】:

    标签: service systemd


    【解决方案1】:

    您可以在服务文件中添加以下内容。

    PartOf=example1.target
    

    这增加了一个ConsistsOf 对目标单元的依赖。

    来自 Systemd 页面

    配置与 Requires= 类似的依赖项,但仅限于停止和重新启动单元。当 systemd 停止或重新启动此处列出的单元时,该操作将传播到该单元。请注意,这是一种单向依赖——对此单位的更改不会影响列出的单位。

    在 a.service 上使用 PartOf=b.service 时,会显示此依赖关系 作为 b.service 的属性列表中的 ConsistsOf=a.service。包括= 不能直接指定依赖。

    阅读更多here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多