Skip to content

Fix runlevel fact on distros without /sbin/runlevel#339

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-runlevel-issue-on-new-distros
Draft

Fix runlevel fact on distros without /sbin/runlevel#339
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-runlevel-issue-on-new-distros

Conversation

Copy link
Copy Markdown

Copilot AI commented May 11, 2026

On newer distros (Fedora 43+), /sbin/runlevel no longer exists, causing facter/openfact to emit sh: line 1: /sbin/runlevel: No such file or directory on every run.

Changes

  • lib/facter/runlevel.rb: Replace hardcoded backtick call to /sbin/runlevel with a two-stage resolution:

    1. Use Facter::Core::Execution.which('runlevel') — if found, exec it (existing behaviour, now safe)
    2. Fall back to systemctl get-default and map the returned systemd target to the equivalent SysV runlevel; returns nil if neither binary is present
    systemd target runlevel
    poweroff.target 0
    rescue.target 1
    multi-user.target 3
    graphical.target 5
    reboot.target 6
  • spec/unit/facter/runlevel_spec.rb: New unit tests covering the runlevel-present path, all mapped systemd targets, an unmapped target, and the no-binary-available case.

Copilot AI linked an issue May 11, 2026 that may be closed by this pull request
- 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 runlevel fact on distros without /sbin/runlevel May 11, 2026
Copilot finished work on behalf of silug May 11, 2026 16:25
Copilot AI requested a review from silug May 11, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runlevel not available on newer distro releases

2 participants