Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Difference between ConditionPathExists= and ConditionPathExists=| in systemd?

I need check a file not exist before i start my service in Systemd. I see two case in [Unit]:

ConditionPathExists=!/tmp/abc

and

ConditionPathExists=|!/tmp/abc

are they the same? Can anybody help me explain if they are different?

like image 643
Thao Nguyen Avatar asked May 19 '16 03:05

Thao Nguyen


People also ask

What is the PID of systemd?

The program systemd is the process with process ID 1. It is responsible for initializing the system in the required way. systemd is started directly by the kernel and resists signal 9, which normally terminates processes. All other programs are either started directly by systemd or by one of its child processes.

Where should systemd unit files go?

Unit files are stored in the /usr/lib/systemd directory and its subdirectories, while the /etc/systemd/ directory and its subdirectories contain symbolic links to the unit files necessary to the local configuration of this host.

What is a unit file?

A unit file is a plain text ini-style file that encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a watched file system path, a timer controlled and supervised by systemd(1), a resource management slice or a group of externally ...

What are three locations for systemd unit files?

Unit files found in this directory have a priority landing between those in /etc/systemd/system and /lib/systemd/system . Files in this location are given less weight than the former location, but more weight than the latter.


1 Answers

Sometime you specify multiple files like:

ConditionPathExists=!/tmp/abc
ConditionPathExists=!/tmp/abe

Now if any of the condition isn't satisfied, it doesn't start service. It's like and operations.

Now if you use:

ConditionPathExists=|!/tmp/abc
ConditionPathExists=|!/tmp/abe

If any of these conditions is satisfied, it will run the service.

Condition checks can be prefixed with a pipe symbol (|) in which case a condition becomes a triggering condition. If at least one triggering condition is defined for a unit, then the unit will be executed if at least one of the triggering conditions apply and all of the non-triggering conditions

It's like OR operations

like image 188
khrm Avatar answered Oct 04 '22 22:10

khrm