LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   How to override the WantedBy directive in systemd units? (https://www.linuxquestions.org/questions/debian-26/how-to-override-the-wantedby-directive-in-systemd-units-4175636225/)

bodqhrohro 08-12-2018 11:04 AM

How to override the WantedBy directive in systemd units?
 
I decided to move some non-critical for my usecases long-starting services to a separate deferred target so they shoudn't delay multi-user.target and graphical.target. So I created
Code:

root@localhost:/home/bodqhrohro# cat /etc/systemd/system/post-graphical-goodies.target
[Unit]
Description=Lazy-load goodies
Wants=graphical.target

and tried to override WantedBy in chosen units to this target (systemctl edit, systemctl disable, systemctl enable). For example, for kdump-tools unit, that is wanted by multi-user.target by default, I added the following drop-in:
Code:

[Install]
WantedBy=post-graphical-goodies.target

And they seem to be overridden well: after executing systemctl reload, the following symlink in /etc/systemd/system/multi-user.target.wants/ disappears. But after reboot it appears again, and both the default target and my custom one are in WantedBy:
Code:

root@localhost:/home/bodqhrohro# systemctl show kdump-tools.service|grep WantedBy
WantedBy=multi-user.target post-graphical-goodies.target

Why? Is this directive cumulative, like ExecStart? I tried to put an empty WantedBy= line before the custom directive to reset it, but that doesn't help.

frankbell 08-12-2018 08:05 PM

This article may help get you started: https://www.digitalocean.com/communi...and-unit-files

Scroll down to the section about "Section Directives."

bodqhrohro 08-13-2018 01:59 PM

Huh, man systemd.unit has an inconspicuous note:

Code:

      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
      AssertPathExists= (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. 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.

So I solved the problem by re-editing the units with a --full option.


All times are GMT -5. The time now is 09:44 AM.