Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

systemd: How to clear an entry when overriding a unit file

Tags:

systemd

A service on my machine has a default unit file that specifies the PIDFile setting in the [Service] section. I want to clear this setting, so that a PID file is not specified for this unit.

I've created my override. Systemd sees it, so it works properly, but I'm not sure what syntax I should use to clear the setting. I've tried this in my override:

[Service]
PIDFile=

But that results in an error:

# systemctl daemon-reload
# systemctl status myservice.service
...
Jan 14 16:15:07 host systemd[1]: [/etc/systemd/system/myservice.service.d/override.conf:1] Not an absolute path, ignoring:

I've also tried PIDFile=none, but that also results in an error. How should I clear this setting?

like image 399
dispree Avatar asked Jan 15 '16 00:01

dispree


People also ask

How do I override a systemd file?

The recommended way is to use the systemctl edit command. This will create an additional folder in /etc/systemd/system and place a file named override. conf in it. This file will then contain only the changes you made.

Where are systemd overrides stored?

Systemd automatically will create a drop-in file in /etc/systemd/system/<service>. d directory. Any statements made in the override file will take priority over the original vendor-supplied unit file usualy located in /usr/lib/systemd/<servcice>.

Where are systemd unit files stored?

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. To explore this, make /etc/systemd the PWD and list its contents.

How do I edit a systemd unit file?

Systemd services can be modified using the systemctl edit command. This creates an override file /etc/systemd/system/httpd. service.


1 Answers

There's some information on the subject at https://www.freedesktop.org/software/systemd/man/systemd.unit.html

Various settings are allowed to be specified more than once, in which case the interpretation depends on the setting. Often, multiple settings form a list, and setting to an empty value "resets", which means that previous assignments are ignored. When this is allowed, it is mentioned in the description of the setting.

However in description of PIDFile directive at https://www.freedesktop.org/software/systemd/man/systemd.service.html there's no information on resetting this value which according to earlier quote means it can't be reset.

Later, in section Example 2. Overriding vendor settings, there's some information on removing entries from lists:

Note that for drop-in files, if one wants to remove entries from a setting that is parsed as a list (and is not a dependency), such as ConditionPathExists= (or e.g. ExecStart= in service units), one needs to first clear the list before re-adding all entries except the one that is to be removed. See below for an example.

Cited example (edited for brevity):

Original unit:

[Unit]
(...)
AssertPathExists=/srv/webserver

Drop-in file:

[Unit]
(...)
AssertPathExists=
AssertPathExists=/srv/www

Also there's following statement:

Note that dependencies (After=, etc.) cannot be reset to an empty list, so dependencies can only be added in drop-ins. If you want to remove dependencies, you have to override the entire unit.

like image 103
Piotr Dobrogost Avatar answered Oct 01 '22 10:10

Piotr Dobrogost