5

I'm attempting to make a systemd service that should only start if a certain file doesn't exist on the file system.

If I use ConditionPathExists this will make the service start only when the file in question exists, which is the opposite behavior of what I want.

Is there a way to invert these conditions?

Mitch
  • 1,188
  • 3
  • 13
  • 24

1 Answers1

10

Yes, use ! to negate the condition:

[Unit]
ConditionPathExists=!/some/path/to/some/file

It's in the manual:

With ConditionPathExists= a file existence condition is checked before a unit is started. If the specified absolute path name does not exist, the condition will fail. If the absolute path name passed to ConditionPathExists= is prefixed with an exclamation mark ("!"), the test is negated, and the unit is only started if the path does not exist.

don_crissti
  • 79,330
  • 30
  • 216
  • 245