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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-04-26 20:58:57 +02:00
parent 2ddbb805ca
commit b01f9f38f2
2 changed files with 12 additions and 3 deletions
+3
View File
@@ -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);
}
}
+9 -3
View File
@@ -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);