Re: [systemd-devel] Alias for template/instance service unit

2021-04-22 Thread Hans Gruber
 Hello,
Thank you for your really appreciated advice. 
I confirm that I misunderstood what "applies to all instances" means.So now 
seems clear. Thanks
But there is something I don't understand.

I have two templates.The second one which is a simple instance of a tail > 
/dev/ttyX under tail@.serviceI renamed it to foo@.service (I don't have 
something which have foo* or bar* as name and previous tail@.service doesn't 
not exist anymore)

I have this [Install] 
Section:WantedBy=getty.targetDefaultInstance=tty12Alias=bar@.service
systemctl enable foo@tty12.service> Created symlink 
/etc/systemd/system/bar@tty12.service => /etc/systemd/system/foo@.service> 
Created symlink /etc/systemd/system/getty.target.wants/foo@tty12.service => 
/etc/systemd/system/foo@service
Systemctl status bar@tty12.service> Loaded: error (Reason: Unit 
bar@tty12.service to load properly: File Exists)
Systemctl start bar@tty12.service = KO> Failed to start bar@tty12.service: Unit 
bar@tty12.service failed to load properly: File Exists.> See system logs and 
systemctl status bar@tty12.service for details
Systemctl start foo@tty12.service = OK
RegardsHans


Le jeudi 22 avril 2021 à 20:49:52 UTC+2, Mantas Mikulėnas 
 a écrit :  
 
 On Thu, Apr 22, 2021 at 9:18 PM Hans Gruber  wrote:

Hello,
I am having problems with the aliases and "Alias=' directive related to the 
template service unit.
According to https://www.freedesktop.org/software/systemd/man/systemd.unit.html

> "A template instance may only be aliased by another template instance, and 
> the instance part must be identical. A template may be aliased by another 
> template (in which case the alias applies to all instances of the template). 
> As a special case, a template instance (e.g. "alias@inst.service") may be a 
> symlink to different template (e.g. "template@inst.service"). In that case, 
> just this specific instance is aliased, while other instances of the template 
> (e.g. "alias@foo.service", "alias@bar.service") are not aliased. Those rule 
> preserve the requirement that the instance (if any) is always uniquely 
> defined for a given unit and all its aliases."
I have exactly these two cases and requirements and cannot find example.
>  "A template may be aliased by another template (in which case the alias 
>applies to all instances of the template)"

eg: How to create an alias using `Alias=` for a service template core@.service 
which will have maybe 8 or 16 instances (eg: core@cpu01.service 
core@cpu02.service ..) which will apply to all instances when enabled using eg 
allcores@.service.


I think you're misunderstanding what "applies to all instances" means. It does 
not give you a super-unit that controls all instances in unison -- rather, it 
gives you a template alias that will provide an alias for *each instance 
individually*.
But one instance is still aliased to one instance. For example, if you alias 
foo@.service => bar@.service, then you automatically get foo@cpu1.service => 
bar@cpu1.service, and so on. That's what template aliases do.
If you want to control multiple instances at once, you might be looking for two 
other features:1. Custom target units, which allow you to *start* all instances 
at once;
2. Wildcard support in `systemctl` commands, which allows you to see the status 
of all loaded instances at once (systemctl status "foo@*.service").
-- 
Mantas Mikulėnas  ___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Alias for template/instance service unit

2021-04-22 Thread Hans Gruber
Hello,
I am having problems with the aliases and "Alias=' directive related to the 
template service unit.
According to https://www.freedesktop.org/software/systemd/man/systemd.unit.html

> "A template instance may only be aliased by another template instance, and 
> the instance part must be identical. A template may be aliased by another 
> template (in which case the alias applies to all instances of the template). 
> As a special case, a template instance (e.g. "alias@inst.service") may be a 
> symlink to different template (e.g. "template@inst.service"). In that case, 
> just this specific instance is aliased, while other instances of the template 
> (e.g. "alias@foo.service", "alias@bar.service") are not aliased. Those rule 
> preserve the requirement that the instance (if any) is always uniquely 
> defined for a given unit and all its aliases."
I have exactly these two cases and requirements and cannot find example.
>  "A template may be aliased by another template (in which case the alias 
>applies to all instances of the template)"

eg: How to create an alias using `Alias=` for a service template core@.service 
which will have maybe 8 or 16 instances (eg: core@cpu01.service 
core@cpu02.service ..) which will apply to all instances when enabled using eg 
allcores@.service.

> "As a special case, a template instance (e.g. "alias@inst.service") may be a 
> symlink to different template (e.g. "template@inst.service"). In that case, 
> just this specific instance is aliased, while other instances of the template 
> (e.g. "alias@foo.service", "alias@bar.service") are not aliased"

eg: How to create an alias using `Alias=` for a service template 
tailoutput@.service which will have maybe 2 instances (eg: 
tailoutput@tty11.service tailoutput@tty12.service ..) which will apply to only 
instance tailoutput@tty12.service when enabled using eg: 
tty12-tailoutput@tty12.service.

I can't apply any alias using "Alias=" directive for two different template 
.service unit.Whatever I use for "Alias=" directive in the two cases inside the 
templates, instance service works, all symlink are created when instance is 
enabled, instance services are started as expected using their names, but all 
alias are always reporting
"Loaded: error (Reason: unit alasname failed to load properly: File exists)"

Alias=allcores@.service
Alias=allcores@%i.serviceAlias=alias@*.service
Alias=tty12-tailoutput@%i.service
Alias=%i-tailoutput@.service
Alias=alias@tty12.serviceAlias=alias-%n

Thank you in advance.
Regards

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel