From: Zbigniew Jędrzejewski-Szmek Date: Tue, 29 Oct 2019 08:39:25 +0000 (+0100) Subject: pid1: log the reason why restart will or will not happen X-Git-Tag: v244~176^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ebc57b89c65dbbfc68b8c395f3c86c1e4a3129d6;p=platform%2Fupstream%2Fsystemd.git pid1: log the reason why restart will or will not happen I was trying to figure out why the restart was not happening, and it wasn't at all obvious. Let's add a nice debug message. --- diff --git a/src/core/service.c b/src/core/service.c index bfbfa4b..b024c94 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1669,21 +1669,28 @@ static int cgroup_good(Service *s) { return r == 0; } -static bool service_shall_restart(Service *s) { +static bool service_shall_restart(Service *s, const char **reason) { assert(s); /* Don't restart after manual stops */ - if (s->forbid_restart) + if (s->forbid_restart) { + *reason = "manual stop"; return false; + } /* Never restart if this is configured as special exception */ - if (exit_status_set_test(&s->restart_prevent_status, s->main_exec_status.code, s->main_exec_status.status)) + if (exit_status_set_test(&s->restart_prevent_status, s->main_exec_status.code, s->main_exec_status.status)) { + *reason = "prevented by exit status"; return false; + } /* Restart if the exit code/status are configured as restart triggers */ - if (exit_status_set_test(&s->restart_force_status, s->main_exec_status.code, s->main_exec_status.status)) + if (exit_status_set_test(&s->restart_force_status, s->main_exec_status.code, s->main_exec_status.status)) { + *reason = "forced by exit status"; return true; + } + *reason = "restart setting"; switch (s->restart) { case SERVICE_RESTART_NO: @@ -1754,8 +1761,19 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) end_state = SERVICE_FAILED; } - if (allow_restart && service_shall_restart(s)) - s->will_auto_restart = true; + if (!allow_restart) + log_unit_debug(UNIT(s), "Service restart not allowed."); + else { + const char *reason; + bool shall_restart; + + shall_restart = service_shall_restart(s, &reason); + log_unit_debug(UNIT(s), "Service will %srestart (%s)", + shall_restart ? "" : "not ", + reason); + if (shall_restart) + s->will_auto_restart = true; + } /* Make sure service_release_resources() doesn't destroy our FD store, while we are changing through * SERVICE_FAILED/SERVICE_DEAD before entering into SERVICE_AUTO_RESTART. */