]> git.ipfire.org Git - thirdparty/systemd.git/commit
service: Don't stop unneeded units needed by restarted service (#7526)
authorMichal Koutný <Werkov@users.noreply.github.com>
Tue, 5 Dec 2017 15:51:19 +0000 (16:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Dec 2017 15:51:19 +0000 (16:51 +0100)
commitdeb4e7080db9dcd2a1d51ccf7c357f88ea863e54
tree89031acc14e8d022c6c4039d4a500affa05db6b9
parent0eb89fe6b6e48177047c8aaa109b3174642c5750
service: Don't stop unneeded units needed by restarted service (#7526)

An auto-restarted unit B may depend on unit A with StopWhenUnneeded=yes.
If A stops before B's restart timeout expires, it'll be started again as part
of B's dependent jobs. However, if stopping takes longer than the timeout, B's
running stop job collides start job which also cancels B's start job. Result is
that neither A or B are active.

Currently, when a service with automatic restarting fails, it transitions
through following states:
        1) SERVICE_FAILED or SERVICE_DEAD to indicate the failure,
        2) SERVICE_AUTO_RESTART while restart timer is running.

The StopWhenUnneeded= check takes place in service_enter_dead between the two
state mentioned above. We temporarily store the auto restart flag to query it
during the check. Because we don't return control to the main event loop, this
new service unit flag needn't be serialized.

This patch prevents the pathologic situation when the service with Restart=
won't restart automatically. As a side effect it also avoid restarting the
dependency unit with StopWhenUnneeded=yes.

Fixes: #7377
src/core/service.c
src/core/service.h
src/core/unit.c
src/core/unit.h