Skip to content

Commit

Permalink
(FACT-852) Support for systemd and systemd_version
Browse files Browse the repository at this point in the history
This commit adds support for systemd and systemd_version facts.
  • Loading branch information
Spredzy committed Mar 12, 2015
1 parent 45352c0 commit 366d9d9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/facter/systemd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Fact: systemd
#
# Purpose:
# Determine whether SystemD is the init system on the node
#
# Resolution:
# Check the name of the process 1 (ps -p 1)
#
# Caveats:
#

# Fact: systemd-version
#
# Purpose:
# Determine the version of systemd installed
#
# Resolution:
# Check the output of systemctl --version
#
# Caveats:
#

Facter.add(:systemd) do
confine :kernel => :linux
setcode do
result = false
init_process_name = Facter::Core::Execution.exec('ps -p 1 -o comm=')
if init_process_name.eql? 'systemd'
result = true
end
end
end

Facter.add(:systemd_version) do
confine :systemd => true
setcode do
version = Facter::Core::Execution.exec("systemctl --version | grep 'systemd' | awk '{ print $2 }'")
end
end
2 changes: 2 additions & 0 deletions schema/facter.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@
"swapsize" : { "type": "string" },
"swapsize_mb" : { "type": "string" },
"system32" : { "type": "string" },
"systemd" : { "type": "boolean" },
"systemd_version" : { "type": "string" },
"system_uptime" : { "type": "object",
"properties" : {
"seconds" : { "type": "integer" },
Expand Down

0 comments on commit 366d9d9

Please sign in to comment.