You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(initsystem): read and stream OpenRC service logs - #525
Service.Logs and Service.StreamLogs returned "not supported" on OpenRC hosts, so k0sproject/k0sctl#1290 (k0sctl logs) can't work on Alpine. This adds ServiceLogs and StreamServiceLogs to initsystem.OpenRC.
OpenRC has no standard log location. Each service script sets one with output_log/error_log or with --stdout/--stderr in the supervisor arguments. The provider sources the conf.d file and the service script in a subshell, as openrc-run does, collects the log files that exist, and runs tail on them. Guessing /var/log/<svc>.log would not work for k0s: its script names the files after the binary, so both k0scontroller and k0sworker log to /var/log/k0s.log and /var/log/k0s.err. A service that logs only to syslog returns an error that wraps errors.ErrUnsupported.
When stdout and stderr go to separate files, Logs returns up to N lines from each file, stdout first. I tested it by hand in an alpine:3.22 container through the localhost client. There is no integration test because the repo has no service-level integration tests yet.
OpenRC has no log location of its own. Each service script sets it
with output_log/error_log or with --stdout/--stderr in the supervisor
arguments. Find the log files by sourcing the conf.d file and the
service script in a subshell, as openrc-run does, and tail them.
The k0s script names its log files after the binary, so both
k0scontroller and k0sworker log to /var/log/k0s.log and
/var/log/k0s.err. A service that logs only to syslog returns an error
that wraps errors.ErrUnsupported.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
OpenRC log discovery mishandles configuration inheritance and supervisor arguments, causing missing or incorrect logs, while stdout ordering and cancellation handling violate the API contracts.
Load rc.conf, the base and instance conf.d files and their runlevel
overrides before the service script. Pass the supervisor arguments
through eval so quoting inside them works. Read only the arguments of
the active supervisor, and let the last --stdout or --stderr win.
Print stdout before stderr regardless of flag order.
Treat a cancelled context during the lookup as a clean stop in
StreamServiceLogs.
Run the lookup script under sh in a test against a temporary OpenRC
tree.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
OpenRC log discovery can miss valid logs or select incorrect paths due to missing helpers, empty-setting parsing, and runlevel fallback bugs, while a test can execute host service configuration.
Initialize OpenRC helpers before discovering conditional log settings
initsystem/openrc.go:126
For a service or conf.d file that sets output_log inside if yesno "$log_enabled"; then ...; fi, discovery skips the assignment and returns errors.ErrUnsupported even when file logging is enabled. This runs under a bare shell without OpenRC's helper functions, and _rig_load hides the command-not-found diagnostic. openrc-run loads its helper libraries before configuration. Initialize the corresponding OpenRC helper environment before sourcing these files, and add a helper-dependent discovery test.
Pick a runlevel conf.d file when it exists, not when sourcing it
succeeds, so a runlevel file that ends in a false test no longer
loads the plain file too. Skip empty output_log and error_log
settings so an empty one does not swallow the next flag. Load the
OpenRC helper functions before the configuration, with a yesno
fallback, so settings that depend on them resolve.
Stub rc-service and rc-status in the lookup test so it never reads
the OpenRC setup of the host that runs it.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
OpenRC log discovery still mishandles configuration precedence, s6 file targets, chroot paths, and attached supervisor options, causing incorrect log selection or unsupported errors for valid configurations.
No open issues 🎉
4 previously missed issues
In code that hasn't changed since last review
Honor RC_PATH precedence when loading log settings
initsystem/openrc.go:124
With RC_PATH=/etc/rc:/etc and a script resolved under /etc/init.d, this lookup misses log settings overridden by /etc/rc/conf.d, so it can tail the wrong file. OpenRC's loader loads configuration roots from RC_PATH in reverse order. Preserve that precedence for both global and service-specific settings rather than reading only the conf.d directory beside the script.
Resolve s6 output_log and error_log targets
initsystem/openrc.go:155
For supervisor=s6 with an existing output_log or error_log, this exits without returning either file, making both log APIs report errors.ErrUnsupported. OpenRC's s6 backend explicitly redirects stdout/stderr to those files when they are not superseded by logger commands; s6 does not always keep separate supervisor-owned logs. Please resolve those effective file targets for s6 and update the test that currently expects them to be ignored.
Parse attached -1 and -2 log path arguments
initsystem/openrc.go:163
OpenRC's supervisor parser uses getopt_long, which accepts attached short-option values such as supervise_daemon_args="-1/var/log/svc.log -2/var/log/svc.err". These cases only match standalone -1 and -2, so that valid configuration produces no discovered files and both log APIs return errors.ErrUnsupported. Handle the attached forms as well.
Resolve log paths relative to the effective chroot
initsystem/openrc.go:171
With chroot=/srv/jail and output_log=/var/log/svc.log, supervise-daemon writes /srv/jail/var/log/svc.log: its log paths are relative to the chroot. This lookup checks /var/log/svc.log on the host instead, so both log APIs report unsupported when the real file exists, or read an unrelated host file. Resolve the effective chroot, including supervisor-argument overrides, before checking and returning log paths.
Return output_log and error_log for s6 unless a logger command
replaces them. s6 redirects before it enters the chroot, so the paths
stay as they are.
For supervise-daemon and start-stop-daemon, read the chroot from the
chroot variable and from --chroot or -r in the arguments, and look for
the log files inside it. Accept short options with an attached value,
such as -1/var/log/svc.log.
Note that the lookup follows the OpenRC 0.63 loader, which does not
read RC_PATH.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Relative log paths are resolved incorrectly against the service directory and chroot, causing both log APIs to report unsupported logging or read the wrong file.
supervise-daemon and start-stop-daemon open the log files after they
change root and directory. Resolve a relative log path from the
service directory, set by the directory variable or by --chdir or -d,
inside the chroot. s6 redirects from its service directory before it
changes root or directory, so resolve its relative paths from there.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because OpenRC log discovery can use incorrect service context or paths, while combined tail output can merge unrelated stdout and stderr entries.
OpenRC log discovery can use incorrect service context or paths, while combined tail output can merge unrelated stdout and stderr entries
This does what openrc-run does, sourcing the same files in the same order. This was tested on alpine and it works for everything I tried. The combined tail output is what it is. OpenRC writes stdout and stderr into separate files and there's no reasonable way to track the exact order they appeared.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Service.LogsandService.StreamLogsreturned "not supported" on OpenRC hosts, so k0sproject/k0sctl#1290 (k0sctl logs) can't work on Alpine. This addsServiceLogsandStreamServiceLogstoinitsystem.OpenRC.OpenRC has no standard log location. Each service script sets one with
output_log/error_logor with--stdout/--stderrin the supervisor arguments. The provider sources the conf.d file and the service script in a subshell, as openrc-run does, collects the log files that exist, and runstailon them. Guessing/var/log/<svc>.logwould not work for k0s: its script names the files after the binary, so bothk0scontrollerandk0sworkerlog to/var/log/k0s.logand/var/log/k0s.err. A service that logs only to syslog returns an error that wrapserrors.ErrUnsupported.When stdout and stderr go to separate files,
Logsreturns up to N lines from each file, stdout first. I tested it by hand in analpine:3.22container through the localhost client. There is no integration test because the repo has no service-level integration tests yet.