ExecCondition 不会阻止服务启动
ExecCondition doesn't prevent start of service
我有一个带有 ExecCondition
的服务文件,当它以 status=1/FAILURE
退出时,不会阻止守护进程的启动。
我认为,根据文档,这应该会阻止守护进程启动以及阻止来自 运行 的所有其他 ExecStartPre
命令。
when an ExecCondition= command exits with exit code 1 through 254 (inclusive), the remaining commands are skipped and the unit is not marked as failed.
我设置了一个每次都应该以明显的方式失败的条件。 ExecCondition=-sh -c 'exit(1)'
这是服务文件(已更改名称以保护无辜者)。
[Unit]
Description=Application
Wants=x-ray.service yankee.service zulu.service
Requires=alpha.service bravo.service
After=x-ray.service charlie.service bravo.service
[Service]
ExecCondition=-sh -c 'exit(1)'
ExecStartPre=-sh -c 'prestartShellScript.sh'
ExecStart=/opt/app/app argument1 argument2
WatchdogSec=10
Restart=always
RestartSec=10
WorkingDirectory=/opt/app
TimeoutSec=10
[Install]
WantedBy=multi-user.target
但是当我启动服务时,使用 systemctl status app
我看到这显示应用程序是 运行,其他进程也是 运行:
Active: active (running) since Fri 2020-02-07 18:06:57 UTC; 6s ago
Process: 33783 ExecCondition=/bin/sh -c exit(1) (code=exited, status=1/FAILURE)
Process: 33796 ExecStartPre=/bin/sh -c prestartShellScript.sh (code=exited, status=0/SUCCESS)
Main PID: 33827 (app)
Tasks: 19 (limit: 4177)
Memory: 101.5M
CGroup: /system.slice/app.service
└─33827 /opt/app/app argument1 argument2
我也将 ExecCondition
更改为 ExecStartPre
,但我看到了相同的行为。
从 -sh
中删除 ExecCondition=-sh -c 'exit 1'
中的 -
Unix 堆栈交换对于 systemd
更活跃一些,所以我在那边交叉张贴。 See answer on stack exchange
我有一个带有 ExecCondition
的服务文件,当它以 status=1/FAILURE
退出时,不会阻止守护进程的启动。
我认为,根据文档,这应该会阻止守护进程启动以及阻止来自 运行 的所有其他 ExecStartPre
命令。
when an ExecCondition= command exits with exit code 1 through 254 (inclusive), the remaining commands are skipped and the unit is not marked as failed.
我设置了一个每次都应该以明显的方式失败的条件。 ExecCondition=-sh -c 'exit(1)'
这是服务文件(已更改名称以保护无辜者)。
[Unit]
Description=Application
Wants=x-ray.service yankee.service zulu.service
Requires=alpha.service bravo.service
After=x-ray.service charlie.service bravo.service
[Service]
ExecCondition=-sh -c 'exit(1)'
ExecStartPre=-sh -c 'prestartShellScript.sh'
ExecStart=/opt/app/app argument1 argument2
WatchdogSec=10
Restart=always
RestartSec=10
WorkingDirectory=/opt/app
TimeoutSec=10
[Install]
WantedBy=multi-user.target
但是当我启动服务时,使用 systemctl status app
我看到这显示应用程序是 运行,其他进程也是 运行:
Active: active (running) since Fri 2020-02-07 18:06:57 UTC; 6s ago
Process: 33783 ExecCondition=/bin/sh -c exit(1) (code=exited, status=1/FAILURE)
Process: 33796 ExecStartPre=/bin/sh -c prestartShellScript.sh (code=exited, status=0/SUCCESS)
Main PID: 33827 (app)
Tasks: 19 (limit: 4177)
Memory: 101.5M
CGroup: /system.slice/app.service
└─33827 /opt/app/app argument1 argument2
我也将 ExecCondition
更改为 ExecStartPre
,但我看到了相同的行为。
从 -sh
中删除 ExecCondition=-sh -c 'exit 1'
-
Unix 堆栈交换对于 systemd
更活跃一些,所以我在那边交叉张贴。 See answer on stack exchange