Fix runlevel fact on distros without /sbin/runlevel#339
Draft
Copilot wants to merge 2 commits into
Draft
Conversation
- Use Facter::Core::Execution.which to check for runlevel binary - Fall back to systemctl get-default with target→runlevel mapping - Use Facter::Core::Execution.exec instead of backticks - Add unit tests covering all scenarios Agent-Logs-Url: https://github.com/simp/pupmod-simp-simplib/sessions/7a97386a-2830-4d7b-b32a-861a349ec7bd Co-authored-by: silug <206992+silug@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix runlevel availability issue on newer distro releases
Fix May 11, 2026
runlevel fact on distros without /sbin/runlevel
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On newer distros (Fedora 43+),
/sbin/runlevelno longer exists, causing facter/openfact to emitsh: line 1: /sbin/runlevel: No such file or directoryon every run.Changes
lib/facter/runlevel.rb: Replace hardcoded backtick call to/sbin/runlevelwith a two-stage resolution:Facter::Core::Execution.which('runlevel')— if found, exec it (existing behaviour, now safe)systemctl get-defaultand map the returned systemd target to the equivalent SysV runlevel; returnsnilif neither binary is presentpoweroff.target0rescue.target1multi-user.target3graphical.target5reboot.target6spec/unit/facter/runlevel_spec.rb: New unit tests covering therunlevel-present path, all mapped systemd targets, an unmapped target, and the no-binary-available case.