Bug 75104 - RFE: [Install] sections in drop-in files are ignored
Summary: RFE: [Install] sections in drop-in files are ignored
Status: RESOLVED FIXED
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-17 16:25 UTC by rfnx.poubelle
Modified: 2017-11-13 19:09 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description rfnx.poubelle 2014-02-17 16:25:14 UTC
Hello,

In order to manage dependency between systemd units, I wanted to use drop-in files to override settings in unit files, but some options are not parsed. 

The manpage says : "Along with a unit file foo.service, a directory foo.service.d/ may exist. All files with the suffix ".conf" from this directory will be parsed after the file itself is parsed. This is useful to alter or add configuration settings to a unit, without having to modify their unit files. Make sure that the file that is included has the appropriate section headers before any directive."

It works for options like "Require" or "After" (Unit section), but not for "RequiredBy" or "WantedBy" (Install section). Maybe it doesn't work with other options but I couldn't try them all. So at the moment I have to stay with the old and not recommended method, as the manpage says : create a unit file with the same name in /etc/systemd/system to override the one in /usr/lib/systemd/system. This way, it works perfectly.




Step to reproduce (on Archlinux) :

- Create a directory in /etc/systemd/system with the name "unit.d" (replace unit with the name of an installed unit, for example postgresql.service)

-create a .conf file which contain a RequiredBy option with the name of an other installed unit)

-do "systemctl daemon-reload" to reload unit files

-do "systemctl status unit" (replace unit with the name of the modified unit, for example postgresql.service) or "systemd-delta" to verify your .conf file has been parsed

-do "systemctl show -p "RequiredBy" unit" (replace unit with the name of the modified unit) to verify if the RequiredBy option has been parsed

Result : RequiredBy isn't modified by the .conf file
Comment 1 Zbigniew Jedrzejewski-Szmek 2014-02-17 16:37:16 UTC
Are you sure that it works at all? If I create a file like:

$ cat /etc/systemd/system/depes.service
[Service]
ExecStart=/bin/depes

[Install]
WantedBy=multi-user.target

$ systemctl show -p WantedBy,RequiredBy depes.service
RequiredBy=
WantedBy=
Comment 2 rfnx.poubelle 2014-02-17 17:25:43 UTC
Yes it works this way for me. In my case, I override the postgresql.service unit file in /usr/lib/systemd/system with the file I created /etc/systemd/system/postgresql.service :

cat /etc/systemd/system/postgresql.service

.include /usr/lib/systemd/system/postgresql.service

[Unit]
Before=dovecot.service

[Install]
RequiredBy=dovecot.service


systemctl show -p RequiredBy,After postgresql.service

RequiredBy=dovecot.service uwsgi@emperor.service
After=network.target systemd-journald.socket basic.target system.slice

-----

Did you do "systemctl daemon-reload" to ensure your unit file was read ? You can also try to disable the unit before creating the file then reenable it to make sure your file is loaded (you can verify this with "systemctl status unit" or "systemd-delta")
Comment 3 Rusty Bird 2014-06-04 12:44:13 UTC
This bug has bitten me too. I work around it by specifying the dependency from the other direction, replacing

  /etc/systemd/foo.service.d/my.conf:
  [Install]
  RequiredBy=bar.service

with

  /etc/systemd/bar.service.d/my.conf:
  [Unit]
  Require=foo.service

though now bar.service will pull in even a disabled foo.service, so it's not quite the same.
Comment 4 Lennart Poettering 2017-11-13 19:09:57 UTC
Implemented now in PR #7158. Closing.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.