service: add 'debug' option to RestartMode=

One of the major pait points of managing fleets of headless nodes is
that when something fails at startup, unless debug level was already
enabled (which usually isn't, as it's a firehose), one needs to manually
enable it and pray the issue can be reproduced, which often is really
hard and time consuming, just to get extra info. Usually the extra log
messages are enough to triage an issue.

This new option makes it so that when a service fails and is restarted
due to Restart=, log level for that unit is set to debug, so that all
setup code in pid1 and sd-executor logs at debug level, and also a new
DEBUG_INVOCATION=1 env var is passed to the service itself, so that it
knows it should start with a higher log level. Once the unit succeeds
or reaches the rate limit the original level is restored.
This commit is contained in:
Luca Boccassi
2024-08-27 12:24:45 +01:00
committed by Luca Boccassi
parent 23e3bddc48
commit 7d8bbfbe08
13 changed files with 163 additions and 23 deletions
+10
View File
@@ -1419,6 +1419,10 @@ static int exec_parameters_serialize(const ExecParameters *p, const ExecContext
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
if (r < 0)
return r;
fputc('\n', f); /* End marker */
return 0;
@@ -1681,6 +1685,12 @@ static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
return r;
sd_id128_to_string(p->invocation_id, p->invocation_id_string);
} else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
r = parse_boolean(val);
if (r < 0)
return r;
p->debug_invocation = r;
} else
log_warning("Failed to parse serialized line, ignoring: %s", l);
}