From b01f9f38f288a32cc0af75ab7066f1d0f37f64b7 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 26 Apr 2022 20:09:18 +0200 Subject: [PATCH] Improve logging of forking services having started and stopped Since a forking service, e.g. a sysv init script, will exit very early we cannot log the same as for regular services "Starting foo[123]", so instead we log "Started bar[321]" when we get the pidfile update and the same when stopping a forking service, log "Stopped bar[321]" when we collect the PID. Signed-off-by: Joachim Wiberg --- plugins/pidfile.c | 3 +++ src/service.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/pidfile.c b/plugins/pidfile.c index 791c611f..2ac5fc39 100644 --- a/plugins/pidfile.c +++ b/plugins/pidfile.c @@ -102,6 +102,9 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask) _d("Forking service %s changed PID from %d to %d", svc->cmd, svc->pid, pid); svc->pid = pid; + + /* Complement log in service.c for non-forking services */ + logit(LOG_CONSOLE | LOG_NOTICE, "Started %s[%d]", svc_ident(svc, NULL, 0), pid); } } diff --git a/src/service.c b/src/service.c index 53991537..5f333919 100644 --- a/src/service.c +++ b/src/service.c @@ -1537,11 +1537,17 @@ void service_monitor(pid_t lost, int status) } /* Forking sysv/services declare themselves with pid:!/path/to/pid.file */ - if (svc_is_starting(svc) && svc_is_forking(svc)) { - svc->pid = 0; /* Expect no more activity from this one */ - return; + if (svc_is_forking(svc)) { + /* Likely start script exiting */ + if (svc_is_starting(svc)) { + svc->pid = 0; /* Expect no more activity from this one */ + return; + } + + logit(LOG_CONSOLE | LOG_NOTICE, "Stopped %s[%d]", svc_ident(svc, NULL, 0), lost); } + /* Terminate any children in the same proess group, e.g. logit */ kill(-svc->pid, SIGKILL);