ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
4fbe94
From d70e1c2eb596b8144197192e2324abbb45f547a6 Mon Sep 17 00:00:00 2001
4fbe94
From: Jonathon Kowalski <bl0pbl33p@gmail.com>
4fbe94
Date: Thu, 17 Jan 2019 17:08:00 +0000
4fbe94
Subject: [PATCH] Change job mode of manager triggered restarts to JOB_REPLACE
4fbe94
4fbe94
Fixes: #11305
4fbe94
Fixes: #3260
4fbe94
Related: #11456
4fbe94
4fbe94
So, here's what happens in the described scenario in #11305. A unit goes
4fbe94
down, and that triggeres stop jobs for the other two units as they were
4fbe94
bound to it. Now, the timer for manager triggered restarts kicks in and
4fbe94
schedules a restart job with the JOB_FAIL job mode. This means there is
4fbe94
a stop job installed on those units, and now due to them being bound to
4fbe94
us they also get a restart job enqueued. This however is a conflicts, as
4fbe94
neither stop can merge into restart, nor restart into stop. However,
4fbe94
restart should be able to replace stop in any case. If the stop
4fbe94
procedure is ongoing, it can cancel the stop job, install itself, and
4fbe94
then after reaching dead finish and convert itself to a start job.
4fbe94
However, if we increase the timer, then it can always take those units
4fbe94
from inactive -> auto-restart.
4fbe94
4fbe94
We change the job mode to JOB_REPLACE so the restart job cancels the
4fbe94
stop job and installs itself.
4fbe94
4fbe94
Also, the original bug could be worked around by bumping RestartSec= to
4fbe94
avoid the conflicting.
4fbe94
4fbe94
This doesn't seem to be something that is going to break uses. That is
4fbe94
because for those who already had it working, there must have never been
4fbe94
conflicting jobs, as that would result in a desctructive transaction by
4fbe94
virtue of the job mode used.
4fbe94
4fbe94
After this change, the test case is able to work nicely without issues.
4fbe94
4fbe94
(cherry picked from commit 03ff2dc71ecb09272d728d458498b44f7f132f51)
4fbe94
4fbe94
Resolves: #1712524
4fbe94
---
4fbe94
 src/core/service.c | 2 +-
4fbe94
 1 file changed, 1 insertion(+), 1 deletion(-)
4fbe94
4fbe94
diff --git a/src/core/service.c b/src/core/service.c
4fbe94
index 3eab749362..8342c131c8 100644
4fbe94
--- a/src/core/service.c
4fbe94
+++ b/src/core/service.c
4fbe94
@@ -2133,7 +2133,7 @@ static void service_enter_restart(Service *s) {
4fbe94
          * restarted. We use JOB_RESTART (instead of the more obvious
4fbe94
          * JOB_START) here so that those dependency jobs will be added
4fbe94
          * as well. */
4fbe94
-        r = manager_add_job(UNIT(s)->manager, JOB_RESTART, UNIT(s), JOB_FAIL, &error, NULL);
4fbe94
+        r = manager_add_job(UNIT(s)->manager, JOB_RESTART, UNIT(s), JOB_REPLACE, &error, NULL);
4fbe94
         if (r < 0)
4fbe94
                 goto fail;
4fbe94