[systemd-devel] Overriding WantedBy and Alias directives

Andrei Borzenkov arvidjaar at gmail.com
Fri Oct 16 11:30:58 PDT 2015


16.10.2015 17:41, Chris Bell пишет:
> Hello,
>
> I currently have a systemd unit that I have to reference a lot which has
> a rather long name. I would prefer to be able to reference this unit as
> a short alias.
>
> Example: I have a container unit called 'systemd-nspawn at gitlab.service'
> and I would like to be able to refer to it as simply 'sd-gitlab.service'
> I've added an override.conf with the following:
>
> [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.

> Alias=sd-gitlab.service         # I've also tried
> Alias=machines.target.wants/gitlab.service and omitted the following
> WantedBy decl.
> WantedBy=machines.target
>
> When I run enable, it does not make the symlinks:
>
> #systemctl enable systemd-nspawn at gitlab.service
> Created symlink from
> /etc/systemd/system/machines.target.wants/systemd-nspawn at gitlab.service
> to /etc/systemd/system/systemd-nspawn at gitlab.service
>
>
> However, if I edit the systemd-nspawn at gitlab.service base unit file
> (systemctl edit --full systemd-nspawn at gitlab.service) and change the
> Install section to:
>
> [Install]
> Alias=gitlab.service          # Only added this one line
> WantedBy=machines.target
>
> and enable the service:
>
> #systemctl enable systemd-nspawn at gitlab.service
> Created symlink from /etc/systemd/system/gitlab.service to
> /etc/systemd/system/systemd-nspawn at gitlab.service.
> Created symlink from
> /etc/systemd/system/machines.target.wants/systemd-nspawn at gitlab.service
> to /etc/systemd/system/systemd-nspawn at gitlab.service.
>
> 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.


More information about the systemd-devel mailing list