Skip to content

Commit

Permalink
feat: use systemctl json output to build up fact for internal services
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaffen committed Nov 14, 2024
1 parent 1fc5d99 commit 91a1643
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/facter/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@
end

Facter.add(:systemd_internal_services) do
require 'json'
confine systemd: true
setcode do
command_output = Facter::Util::Resolution.exec(
'systemctl list-unit-files --no-legend --no-pager "systemd-*" -t service --state=enabled,disabled,enabled-runtime,indirect'
)
lines = command_output.lines.lazy.map { |line| line.split(%r{\s+}) }
lines.each_with_object({}) do |(service, status, *), result|
result[service] = status
end
command_output = Facter::Util::Resolution.exec('systemctl list-unit-files "systemd-*" -t service --state=enabled,disabled,enabled-runtime,indirect -o json')
JSON.parse(command_output).to_h { |service| [service['unit_file'], service['state']] }
end
end

0 comments on commit 91a1643

Please sign in to comment.