Search code examples
linuxshellsystemd

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 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


Solution

  • You could run the shell.

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