You are not logged in.

#1 2013-09-05 14:52:01

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

[Solved] Systemd OnFailure= Clarification

I have a service unit, B, that I want to trigger if another one, A, fails.

The systemd.unit man page says this about OnFailure

OnFailure=
           Lists one or more units that are activated when this unit enters the 'failed' state.

I have this in the A.service file:

[Unit]
...
Conflicts=B.service
Before=B.service
OnFailure=B.service
...

There is also a corresponding Conflicts and After in B.service file.

I have tried with both B enabled and disabled, and each time I get the following error if A fails:

Sep 05 15:08:16 SKANKY systemd[1]: Unit A.service entered failed state.
Sep 05 15:08:16 SKANKY systemd[1]: Triggering OnFailure= dependencies of A.service.
Sep 05 15:08:16 SKANKY systemd[1]: Failed to enqueue OnFailure= job: File exists

I've obviously misunderstood something and misconfigured something, but I can't see what. Web and forum searches don't help.
I can post the actual files, but my misunderstanding seems to be more general than specific here, so I'd like to avoid sidetracks into the specifics of the services involved.

Last edited by skanky (2013-09-08 10:15:42)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#2 2013-09-08 01:39:20

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,132

Re: [Solved] Systemd OnFailure= Clarification

I don't think you can use Before and After like that - take a look at the manual page for systemd.unit. You are basically saying that A must be started up before B is started and that A conflicts with B, for example. But that doesn't seem to make sense.

Why isn't OnFailed enough?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2013-09-08 10:00:21

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: [Solved] Systemd OnFailure= Clarification

Thanks for the reply. 

I got the need for Before/After from the manual, though I might be misunderstanding it :

Conflicts=
           Configures negative requirement dependencies. If a unit has a Conflicts= setting on
           another unit, starting the former will stop the latter and vice versa. Note that this
           setting is independent of and orthogonal to the After= and Before= ordering
           dependencies.

           If a unit A that conflicts with a unit B is scheduled to be started at the same time
           as B, the transaction will either fail (in case both are required part of the
           transaction) or be modified to be fixed (in case one or both jobs are not a required
           part of the transaction). In the latter case the job that is not the required will be
           removed, or in case both are not required the unit that conflicts will be started and
           the unit that is conflicted is stopped.

Why isn't OnFailed enough?

It might be, I can't remember if I tried that on its own. I was hoping the error message would suggest a course though, as there's a lot of combinations of settings here that all seem valid and don't seem to ruled out by the documentation. Some of which have thrown up that error message. I'm trying new things out though, as I get a chance.

EDIT:

Okay, I removed all the conflicts stuff and it worked. I'll mark as solved, though I'm still not quite sure I'm completely sure how it all ties together - eg why having Conflicts etc. stops OnFailure working.
Thanks for the nudge though.

Last edited by skanky (2013-09-08 10:15:25)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#4 2013-09-08 15:43:44

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,132

Re: [Solved] Systemd OnFailure= Clarification

Yes. I see what you mean. I'm glad you found a solution and wish I could explain it. I find that systemd has a great deal of documentation but that it is often difficult to use effectively. Perhaps I just haven't read enough of it but I find two problems. First, I'm often unsure which bit of documentation to consult (man systemd.unit? systemd.service? systemd.something-else?)

EDIT: There was a second... I think the second is that it often describes stuff very abstractly and doesn't include enough examples. I think examples make manual pages much, much easier to understand and systemd's seem rather lacking in this respect.

Last edited by cfr (2013-09-08 20:05:32)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#5 2013-09-08 19:34:57

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: [Solved] Systemd OnFailure= Clarification

Yes, I've tried reading quite a lot, but a lot of it doesn't stick (unless it's something I need to use straight away) and when I need to look something up, I often have to hunt around to find any/all the relevant information. It's only a small proportion of the time that I have these issues though, and I might be doing something that may be slightly unusual.

Again, thanks for the help - I obviously hadn't tried OnFailure= on it's own, so the suggestion was very useful.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

Board footer

Powered by FluxBB