|
|
ff2b41 |
From 273d69011bf2a8abfcef71e33e6b6ae3323dfc34 Mon Sep 17 00:00:00 2001
|
|
|
ff2b41 |
From: Jouke Witteveen <j.witteveen@gmail.com>
|
|
|
ff2b41 |
Date: Sat, 1 Oct 2016 14:06:48 +0200
|
|
|
ff2b41 |
Subject: [PATCH] service: fix main processes exit behavior for type notify
|
|
|
ff2b41 |
services
|
|
|
ff2b41 |
|
|
|
ff2b41 |
Before this commit, when the main process of a Type=notify service exits the
|
|
|
ff2b41 |
service would enter a running state without passing through the startup post
|
|
|
ff2b41 |
state. This meant ExecStartPost= from being executed and allowed follow-up
|
|
|
ff2b41 |
units to start too early (before the ready notification).
|
|
|
ff2b41 |
Additionally, when RemainAfterExit=yes is used on a Type=notify service, the
|
|
|
ff2b41 |
exit status of the main process would be disregarded.
|
|
|
ff2b41 |
|
|
|
ff2b41 |
After this commit, an unsuccessful exit of the main process of a Type=notify
|
|
|
ff2b41 |
service puts the unit in a failed state. A successful exit is inconsequential
|
|
|
ff2b41 |
in case RemainAfterExit=yes. Otherwise, when no ready notification has been
|
|
|
ff2b41 |
received, the unit is put in a failed state because it has never been active.
|
|
|
ff2b41 |
When all processes in the cgroup of a Type=notify service are gone and no ready
|
|
|
ff2b41 |
notification has been received yet, the unit is also put in a failed state.
|
|
|
ff2b41 |
|
|
|
ff2b41 |
(cherry picked from commit 3d474ef7a687e2052aa303e0f95893b2fc610475)
|
|
|
ff2b41 |
|
|
|
ff2b41 |
Related: #1733998
|
|
|
ff2b41 |
---
|
|
|
ff2b41 |
src/core/service.c | 24 +++++++++++++++++++-----
|
|
|
ff2b41 |
1 file changed, 19 insertions(+), 5 deletions(-)
|
|
|
ff2b41 |
|
|
|
ff2b41 |
diff --git a/src/core/service.c b/src/core/service.c
|
|
|
ff2b41 |
index 84a5aeb072..b6f302ec33 100644
|
|
|
ff2b41 |
--- a/src/core/service.c
|
|
|
ff2b41 |
+++ b/src/core/service.c
|
|
|
ff2b41 |
@@ -1531,7 +1531,9 @@ static void service_enter_running(Service *s, ServiceResult f) {
|
|
|
ff2b41 |
else
|
|
|
ff2b41 |
service_set_state(s, SERVICE_RUNNING);
|
|
|
ff2b41 |
|
|
|
ff2b41 |
- } else if (s->remain_after_exit)
|
|
|
ff2b41 |
+ } else if (f != SERVICE_SUCCESS)
|
|
|
ff2b41 |
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
ff2b41 |
+ else if (s->remain_after_exit)
|
|
|
ff2b41 |
service_set_state(s, SERVICE_EXITED);
|
|
|
ff2b41 |
else
|
|
|
ff2b41 |
service_enter_stop(s, SERVICE_SUCCESS);
|
|
|
ff2b41 |
@@ -2561,10 +2563,12 @@ static void service_notify_cgroup_empty_event(Unit *u) {
|
|
|
ff2b41 |
|
|
|
ff2b41 |
case SERVICE_START:
|
|
|
ff2b41 |
case SERVICE_START_POST:
|
|
|
ff2b41 |
- /* If we were hoping for the daemon to write its PID file,
|
|
|
ff2b41 |
- * we can give up now. */
|
|
|
ff2b41 |
- if (s->pid_file_pathspec) {
|
|
|
ff2b41 |
- log_unit_warning(u->id, "%s never wrote its PID file. Failing.", UNIT(s)->id);
|
|
|
ff2b41 |
+ if (s->type == SERVICE_NOTIFY)
|
|
|
ff2b41 |
+ /* No chance of getting a ready notification anymore */
|
|
|
ff2b41 |
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_PROTOCOL);
|
|
|
ff2b41 |
+ else if (s->pid_file_pathspec) {
|
|
|
ff2b41 |
+ /* Give up hoping for the daemon to write its PID file */
|
|
|
ff2b41 |
+ log_unit_warning(u->id, "Daemon never wrote its PID file. Failing.");
|
|
|
ff2b41 |
|
|
|
ff2b41 |
service_unwatch_pid_file(s);
|
|
|
ff2b41 |
if (s->state == SERVICE_START)
|
|
|
ff2b41 |
@@ -2699,6 +2703,16 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
|
|
ff2b41 |
else
|
|
|
ff2b41 |
service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
ff2b41 |
break;
|
|
|
ff2b41 |
+ } else if (s->type == SERVICE_NOTIFY) {
|
|
|
ff2b41 |
+ /* Only enter running through a notification, so that the
|
|
|
ff2b41 |
+ * SERVICE_START state signifies that no ready notification
|
|
|
ff2b41 |
+ * has been received */
|
|
|
ff2b41 |
+ if (f != SERVICE_SUCCESS)
|
|
|
ff2b41 |
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, f);
|
|
|
ff2b41 |
+ else if (!s->remain_after_exit)
|
|
|
ff2b41 |
+ /* The service has never been active */
|
|
|
ff2b41 |
+ service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_PROTOCOL);
|
|
|
ff2b41 |
+ break;
|
|
|
ff2b41 |
}
|
|
|
ff2b41 |
|
|
|
ff2b41 |
/* Fall through */
|