[systemd-devel] Overriding WantedBy and Alias directives

Chris Bell cwbell at narmos.org
Fri Oct 16 07:41:44 PDT 2015


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.
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?
Also, is there any way to specify a unit alias within an override.conf?

Thanks in advance!




More information about the systemd-devel mailing list