如何否定在 systemd 服务的 ExecCondition 中使用的命令的退出代码。

huangapple go评论70阅读模式
英文:

How can I negate the exit code of a command used in ExecCondition of a systemd service

问题

I would like to negate the exit code of a command used in ExecCondition of a systemd service. However, I cannot use a "!" before the command because this character is used by systemd for something slightly different (proceed even if the command fails [1]).

[Unit]
Description=Negated Exec Condition

[Service]
Type=oneshot

ExecCondition=/usr/bin/command # 如何否定退出码?

ExecStart=...

[Install]
WantedBy=default.target

[1] https://www.freedesktop.org/software/systemd/man/systemd.service.html

英文:

I would like to negate the exit code of a command used in ExecCondition of a systemd service. However, I cannot use a "!" before the command, because this character is used by systemd for something slightly else (proceed, even if command fails [1]).

[Unit]
Description=Negated Exec Condition

[Service]
Type=oneshot

ExecCondition=/usr/bin/command # How can I negate the exit code?

ExecStart=...

[Install]
WantedBy=default.target

[1] https://www.freedesktop.org/software/systemd/man/systemd.service.html

答案1

得分: 0

你可以运行 shell。

ExecCondition=/bin/sh -c '! "$@"' -- /usr/bin/command
英文:

You could run the shell.

ExecCondition=/bin/sh -c '! "$@"' -- /usr/bin/command

huangapple
  • 本文由 发表于 2023年4月19日 22:27:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76055699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定