[systemd-devel] Overriding WantedBy and Alias directives

Chris Bell cwbell at narmos.org
Fri Oct 16 11:48:49 PDT 2015


On 2015-10-16 18:30, Andrei Borzenkov wrote:
> 16.10.2015 17:41, Chris Bell пишет:
>> [Install]
>> WantedBy=                       # To clear out previous wantedby 
>> params,
>> though this doesn't seem to work like that. Documentation doesn't say 
>> it
>> should, so I'm not surprised.
> 
> Only selected directives can be cleared this way.
> 
>> Is there a way I can have it only enable the alias of the unit? Or do
>> both have to be enabled?
> 
> The problem is that Alias is just a symlink to "primary" unit file.
> But in case of instantiated template no primary unit file exists at
> all. So there would really be nothing to link to.
> 
> But it seems that even if I create link foo at bar.service to
> foo at .service it still wants to enable template, not instantiated unit.
> 
>> Also, is there any way to specify a unit alias within an 
>> override.conf?
>> 
> 
> Seems to be ignored, at least [Install] section.

So, in short, systemd doesn't provide quite the functionality I am 
looking for here. I am able to enable only the alias by using:

[Install]
Alias=machines.target.wants/gitlab.service

and not using 'WantedBy.' This achieves part of what I'd like to 
accomplish. However, it doesn't end up being any more convenient from 
most points of view. I was hoping that, if I aliased 
'systemd-nspawn at gitlab.service' to 'gitlab.service' that I could then 
use:

# systemctl <command> gitlab.service

and have it know that I'm talking about gitlab.service. And I would 
really like to be able to do this with overrides. Why? Because I'd like 
to be able to have conveniently-named service identifiers that point to 
pre-defined services/templates/etc. I would like to manage 
'systemd-nspawn at gitlab.service' as 'gitlab.service' without having to 
copy the systemd-nspawn template to a brand new gitlab.service. If I 
create one-off copies, then if the template is updated those changes 
don't propagate to the one-off copy. I guess I could accomplish this 
with symlinks in the /etc/systemd dir (gitlab.service -> 
systemd-nspawn at gitlab.service) but that's not a nice, clean, or good way 
to do it. Are there any other solutions/workarounds? Or is systemd just 
not intended to be used like this?

Thanks again!

Chris


More information about the systemd-devel mailing list