[systemd-devel] [PATCH] core: get rid the start job when transitioning to deactivating
Lukáš Nykrýn
lnykryn at redhat.com
Fri Jul 19 00:17:47 PDT 2013
Dne 18.7.2013 20:02, Lennart Poettering napsal(a):
> On Thu, 18.07.13 17:04, Michal Sekletar (msekleta at redhat.com) wrote:
>
>> When dependency unit is configured with StopWhenUnneeded=yes and
>> activation of main unit fails, e.g. start timeout occurs, then
>> dependencies are never stopped. This happens because start job for
>> the main unit is still around.
>> ---
>> src/core/unit.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/core/unit.c b/src/core/unit.c
>> index 0e9329f..d5c89a4 100644
>> --- a/src/core/unit.c
>> +++ b/src/core/unit.c
>> @@ -1461,7 +1461,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
>> else if (u->job->state == JOB_RUNNING && ns != UNIT_ACTIVATING) {
>> unexpected = true;
>>
>> - if (UNIT_IS_INACTIVE_OR_FAILED(ns))
>> + if (UNIT_IS_INACTIVE_OR_FAILED(ns) || UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
>> job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true);
>> }
>>
> Hmm, so UNIT_IS_INACTIVE_OR_DEACTIVATING() actually tests for a superset
> of UNIT_IS_INACTIVE_OR_FAILED(), so oring them is unnecessary.
>
> I am not entirely grokking the patch though. So far the idea was that if
> a unit is being deactviated while a start job is queued that we then
> simply wait until the deactivation is complete and then execute the
> start job. This would break with your patch though...
>
> Hmm, can you eleraborate on the actual problem you are trying to solve=
> I don't get it so far ;-)
>
> Thanks,
>
> Lennart
>
Dne 18.7.2013 20:02, Lennart Poettering napsal(a):
> On Thu, 18.07.13 17:04, Michal Sekletar (msekleta at redhat.com) wrote:
>
>> When dependency unit is configured with StopWhenUnneeded=yes and
>> activation of main unit fails, e.g. start timeout occurs, then
>> dependencies are never stopped. This happens because start job for
>> the main unit is still around.
>> ---
>> src/core/unit.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/core/unit.c b/src/core/unit.c
>> index 0e9329f..d5c89a4 100644
>> --- a/src/core/unit.c
>> +++ b/src/core/unit.c
>> @@ -1461,7 +1461,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
>> else if (u->job->state == JOB_RUNNING && ns != UNIT_ACTIVATING) {
>> unexpected = true;
>>
>> - if (UNIT_IS_INACTIVE_OR_FAILED(ns))
>> + if (UNIT_IS_INACTIVE_OR_FAILED(ns) || UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
>> job_finish_and_invalidate(u->job, ns == UNIT_FAILED ? JOB_FAILED : JOB_DONE, true);
>> }
>>
> Hmm, so UNIT_IS_INACTIVE_OR_DEACTIVATING() actually tests for a superset
> of UNIT_IS_INACTIVE_OR_FAILED(), so oring them is unnecessary.
>
> I am not entirely grokking the patch though. So far the idea was that if
> a unit is being deactviated while a start job is queued that we then
> simply wait until the deactivation is complete and then execute the
> start job. This would break with your patch though...
>
> Hmm, can you eleraborate on the actual problem you are trying to solve=
> I don't get it so far ;-)
>
> Thanks,
>
> Lennart
>
Hi,
when service has StopWhenUnneeded=yes and it is requested by forking
service, which fails during initialization, the first unit is not stopped.
Reproducer:
-bash-4.2# more /etc/systemd/system/test*
::::::::::::::
/etc/systemd/system/test.service
::::::::::::::
[Unit]
Description=aaa
Requires=testb.service
[Service]
Type=forking
ExecStart=/bin/sleep 50
TimeoutStartSec=3
::::::::::::::
/etc/systemd/system/testb.service
::::::::::::::
[Unit]
Description=aaa
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/echo hej
ExecStop=/bin/echo hou
-bash-4.2# systemctl status testb test
testb.service - aaa
Loaded: loaded (/etc/systemd/system/testb.service; static)
Active: inactive (dead)
test.service - aaa
Loaded: loaded (/etc/systemd/system/test.service; static)
Active: inactive (dead)
-bash-4.2# systemctl start test
Job for test.service failed. See 'systemctl status test.service' and
'journalctl -xn' for details.
-bash-4.2# systemctl status testb test
testb.service - aaa
Loaded: loaded (/etc/systemd/system/testb.service; static)
Active: active (exited) since Thu 2013-07-18 15:34:34 CEST; 7s ago
Process: 45 ExecStart=/bin/echo hej (code=exited, status=0/SUCCESS)
Jul 18 15:34:34 mycontainer systemd[1]: Starting aaa...
Jul 18 15:34:34 mycontainer systemd[1]: Started aaa.
test.service - aaa
Loaded: loaded (/etc/systemd/system/test.service; static)
Active: failed (Result: timeout) since Thu 2013-07-18 15:34:37 CEST;
4s ago
Process: 46 ExecStart=/bin/sleep 50 (code=killed, signal=TERM)
Jul 18 15:34:34 mycontainer systemd[1]: Starting aaa...
Jul 18 15:34:37 mycontainer systemd[1]: test.service operation timed
out. Terminating.
Jul 18 15:34:37 mycontainer systemd[1]: Failed to start aaa.
Jul 18 15:34:37 mycontainer systemd[1]: Unit test.service entered failed
state.
More information about the systemd-devel
mailing list