Bug 798638

Summary: DOC: clarify Requires with respect to later failures of the required unit
Product: [Fedora] Fedora Reporter: cornel panceac <cpanceac>
Component: systemdAssignee: systemd-maint
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 18CC: bochecha, johannbg, metherid, mschmidt, notting, plautrba, systemd-maint, zbyszek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-12-09 01:33:55 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 784611    
Attachments:
Description Flags
test scripts and service files kindly provided by bochecha none

Description cornel panceac 2012-02-29 13:20:41 UTC
Created attachment 566547 [details]
test scripts and service files kindly provided by bochecha

Description of problem:
I could not find a way to force a unit to fail if it's required service fails.

bochecha created some test services and scripts and even if foo requires bar, when bar fails, foo keeps running. The man page states that:

" Requires=
           Configures requirement dependencies on other units. If this unit gets activated, the units listed here will be activated as well. If one of the other
           units gets deactivated or its activation fails, this unit will be deactivated.[...]"

Also, i believe that the logic is broken, because: if bar service never reaches the active state, foo is started anyway, just because bar attempts to activate .

The expected behaviour is that foo runs if bar is 100% active.

Version-Release number of selected component (if applicable):

# rpm -q systemd
systemd-37-13.fc16.i686

How reproducible:
always


Steps to Reproduce:
1.create the services and scripts from the attached file
2.place files where they belong (scripts in root, services in /etc/systemd/sytem)
3.run foo.service, check the status of bar.service after the 10 seconds sleep, then check the status of bar.service
  
Actual results:
foo is active, bar is failed


Expected results:
both are failed

Additional info:

I also replaced in foo.service, Requires with After.

foo started fine, bar never started. The man page says that:

"If a unit foo.service contains a setting Before=bar.service and both units are being started,
           bar.service's start-up is delayed until foo.service is started up."

This is not what happened. We need clarification on these subjects.

Comment 1 Michal Schmidt 2012-02-29 15:38:14 UTC
(In reply to comment #0)
> Created attachment 566547 [details]
> test scripts and service files kindly provided by bochecha
> 
> Description of problem:
> I could not find a way to force a unit to fail if it's required service fails.

Try using BindTo= instead of Requires=.

> bochecha created some test services and scripts and even if foo requires bar,
> when bar fails, foo keeps running. The man page states that:
> 
> " Requires=
>            Configures requirement dependencies on other units. If this unit
> gets activated, the units listed here will be activated as well. If one of the
> other
>            units gets deactivated or its activation fails, this unit will be
> deactivated.[...]"

Hmm, the manpage should be clarified here. There is a difference between requested deactivation (systemctl stop ...) and sudden deactivation (the process itself quits).

> Also, i believe that the logic is broken, because: if bar service never reaches
> the active state, foo is started anyway, just because bar attempts to activate
> .

If you want to wait for bar to activate before starting foo, you need to complement the requirement dependency with an ordering dependency (After=...).

> I also replaced in foo.service, Requires with After.
> 
> foo started fine, bar never started.

This is expected, because when you dropped the requirement dependency, systemd had no reason to pull bar into the transaction.

> "If a unit foo.service contains a setting Before=bar.service and both units are
> being started,
>            bar.service's start-up is delayed until foo.service is started up."
> 
> This is not what happened. We need clarification on these subjects.

Both units were not being started. The antecedent of the implication did not hold.

Comment 2 cornel panceac 2012-02-29 15:50:40 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > Created attachment 566547 [details]
> > test scripts and service files kindly provided by bochecha
> > 
> > Description of problem:
> > I could not find a way to force a unit to fail if it's required service fails.
> 
> Try using BindTo= instead of Requires=.

bochecha tried that and got same results: bar failed, foo still active.
> 
> > bochecha created some test services and scripts and even if foo requires bar,
> > when bar fails, foo keeps running. The man page states that:
> > 
> > " Requires=
> >            Configures requirement dependencies on other units. If this unit
> > gets activated, the units listed here will be activated as well. If one of the
> > other
> >            units gets deactivated or its activation fails, this unit will be
> > deactivated.[...]"
> 
> Hmm, the manpage should be clarified here. There is a difference between
> requested deactivation (systemctl stop ...) and sudden deactivation (the
> process itself quits).
> 
> > Also, i believe that the logic is broken, because: if bar service never reaches
> > the active state, foo is started anyway, just because bar attempts to activate
> > .
> 
> If you want to wait for bar to activate before starting foo, you need to
> complement the requirement dependency with an ordering dependency (After=...).
> 
> > I also replaced in foo.service, Requires with After.
> > 
> > foo started fine, bar never started.
> 
> This is expected, because when you dropped the requirement dependency, systemd
> had no reason to pull bar into the transaction.
> 
> > "If a unit foo.service contains a setting Before=bar.service and both units are
> > being started,
> >            bar.service's start-up is delayed until foo.service is started up."
> > 
> > This is not what happened. We need clarification on these subjects.
> 
> Both units were not being started. The antecedent of the implication did not
> hold.

Here it seems i've missed an "and" :)

Comment 3 cornel panceac 2012-02-29 16:09:59 UTC
So, if i put both After and Requires, if bar fails, foo fails, if bar exits with SUCCESS, foo is active and running. It looks more complex than it should be, but i assume i don't see the whole picture. It would be great if this Requires *and* After would be more visible :)

Comment 4 Michal Schmidt 2012-02-29 16:41:20 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > Try using BindTo= instead of Requires=.
> 
> bochecha tried that and got same results: bar failed, foo still active.

Works for me. foo is stopped as soon as bar fails.
Maybe he forgot to do "systemctl daemon-reload" after modifying the unit file?

Comment 5 cornel panceac 2012-02-29 18:46:34 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > Try using BindTo= instead of Requires=.
> > 
> > bochecha tried that and got same results: bar failed, foo still active.
> 
> Works for me. foo is stopped as soon as bar fails.
> Maybe he forgot to do "systemctl daemon-reload" after modifying the unit file?

Indeed, works here too. Probably he forgot the reload or i misunderstood him.

Comment 6 Mathieu Bridon 2012-03-01 08:15:46 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > Try using BindTo= instead of Requires=.
> > 
> > bochecha tried that and got same results: bar failed, foo still active.
> 
> Works for me. foo is stopped as soon as bar fails.
> Maybe he forgot to do "systemctl daemon-reload" after modifying the unit file?

Nope, I did reload.

However, I had used BindsTo= instead of BindTo= :)

<off-topic rant>
This is one of my main pet peeves with systemd: some directives are vers at the 3rd person like "Requires", others are infinitive verbs like "BindTo" or "RemainAfterExit", which causes me to mistype them very often as I'm writing lots of unit files for our in-house software
</off-topic rant>

(In reply to comment #1)
> > " Requires=
> >            Configures requirement dependencies on other units. If this unit
> > gets activated, the units listed here will be activated as well. If one of the
> > other
> >            units gets deactivated or its activation fails, this unit will be
> > deactivated.[...]"
> 
> Hmm, the manpage should be clarified here. There is a difference between
> requested deactivation (systemctl stop ...) and sudden deactivation (the
> process itself quits).

Thanks Michal for confirming we had misunderstood something.

What does the last quoted sentence mean then? That if in the same transaction we are starting foo.service (which requires bar.service) and stopping bar.service, then foo.service will be deactivated?

Or this sentence simply be dropped altogether as it is too confusing?

Comment 7 Fedora End Of Life 2013-01-16 17:41:56 UTC
This message is a reminder that Fedora 16 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 16. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '16'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 16's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 16 is end of life. If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora, you are encouraged to click on 
"Clone This Bug" and open it against that version of Fedora.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping

Comment 8 Zbigniew Jędrzejewski-Szmek 2013-12-09 01:33:55 UTC
BindTo was renamed to BindsTo in v186-85-g7f2cdda, and the documentation was also updated somewhere around that time. Please file new bugs if something is still missing.