【问题标题】:How to ignore a failure of an 'ExecStart' in Systemd如何忽略 Systemd 中的“ExecStart”失败
【发布时间】:2019-11-17 14:24:21
【问题描述】:

我正在尝试创建一个使用ExecStart 运行多个脚本的服务,其中一些可能会失败。我需要忽略这些失败的脚本并为服务返回成功。

以前我使用upstart,这就是我实现它的方法。

start on runlevel [23]
stop on shutdown

script
    set +e # Disable exit on non 0
    stop sys_process_script
    start sys_init_script
    start sys_process_script
    set -e # Enable exit on non 0
end script

但我不知道如何忽略失败的脚本。这是我目前的实现。

[Unit]
Description=System starter

[Service]
Type=forking
ExecStart=/bin/systemctl stop sys_process_script
ExecStart=/bin/systemctl start sys_init_script
ExecStart=/bin/systemctl start sys_process_script

如果在systemctl.service - onFailure 中失败,是否有任何方法可以忽略脚本?

【问题讨论】:

    标签: ubuntu-16.04 systemd ubuntu-18.04 systemctl


    【解决方案1】:

    内联包装的简单方法

    ExecStart=/bin/sh -c"command_which_will_fail; exit 0;"
    

    【讨论】:

      【解决方案2】:

      让该二进制可执行文件或脚本返回零 (0) 的退出代码。

      【讨论】:

        猜你喜欢
        • 2016-08-25
        • 2016-01-10
        • 2018-06-20
        • 1970-01-01
        • 1970-01-01
        • 2021-10-28
        • 2018-11-14
        • 1970-01-01
        • 2012-06-17
        相关资源
        最近更新 更多