首页 > 解决方案 > 如何忽略 Systemd 中的“ExecStart”失败

问题描述

我正在尝试创建一个运行多个脚本的服务,其中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如果 in或 in失败,是否有任何方法可以忽略脚本.service - onFailure

标签: ubuntu-16.04systemdubuntu-18.04systemctl

解决方案


内联包装的简单方法

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

推荐阅读