ubuntu-16.04 - 如何忽略 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
?
解决方案
内联包装的简单方法
ExecStart=/bin/sh -c"command_which_will_fail; exit 0;"
推荐阅读
- python - 有人可以解释批量大小和每个时期的步数之间的关系吗?
- windows - Rename-Item:访问路径被拒绝(Flutter升级)
- python - 删除多个文件夹中的图像(Python)
- c++ - 是否可以使用一个元组来索引另一个元组?
- javascript - 输入文本 - “defaultValue”未加载状态值,“value”未在更改时更新
- c# - 删除字节数组中的前导 0
- node.js - zeromq.js - 等待连接
- javascript - 在Javascript中将给定值除以.style.width
- python - 无法导入语音识别
- r - solve() 函数在 GNU R 3.6.3 中冻结 CLI