From e2ef15480abaf5a10404ec4c2c049d82aae47b68 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Thu, 12 Mar 2015 10:17:33 +0100 Subject: (FACT-852) Support for systemd and systemd_version This commit adds support for systemd and systemd_version facts. --- lib/facter/systemd.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/facter/systemd.rb (limited to 'lib') diff --git a/lib/facter/systemd.rb b/lib/facter/systemd.rb new file mode 100644 index 0000000..3ac0a1e --- /dev/null +++ b/lib/facter/systemd.rb @@ -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 -- cgit v1.2.3 From b19ae68789e2a7abe0368d710f5860eef2a70a1d Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Fri, 19 Feb 2016 09:14:51 +0100 Subject: Simplify systemd facts following puppetlabs/facter#871 comments --- lib/facter/systemd.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/facter/systemd.rb b/lib/facter/systemd.rb index 3ac0a1e..b4b11fb 100644 --- a/lib/facter/systemd.rb +++ b/lib/facter/systemd.rb @@ -23,17 +23,13 @@ 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 + Facter::Core::Execution.exec('ps -p 1 -o comm=') == 'systemd' end end Facter.add(:systemd_version) do confine :systemd => true setcode do - version = Facter::Core::Execution.exec("systemctl --version | grep 'systemd' | awk '{ print $2 }'") + Facter::Core::Execution.exec("systemctl --version | grep 'systemd' | awk '{ print $2 }'") end end -- cgit v1.2.3 From aeff226c587ec52adfdadc707ab97028c7ccaf9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Tue, 26 Jul 2016 00:01:57 +0200 Subject: only use awk, instead of grep and awk (#9) This reduces a pipe, by only using `awk` for both of operations that of `grep`, and that of `awk`. --- lib/facter/systemd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/facter/systemd.rb b/lib/facter/systemd.rb index b4b11fb..d488efb 100644 --- a/lib/facter/systemd.rb +++ b/lib/facter/systemd.rb @@ -30,6 +30,6 @@ end Facter.add(:systemd_version) do confine :systemd => true setcode do - Facter::Core::Execution.exec("systemctl --version | grep 'systemd' | awk '{ print $2 }'") + Facter::Core::Execution.exec("systemctl --version | awk '/systemd/{ print $2 }'") end end -- cgit v1.2.3 From b2f44d4832a771dde6ebea86f70811de8b4c1f26 Mon Sep 17 00:00:00 2001 From: Peter Souter Date: Wed, 24 Aug 2016 20:04:10 +0100 Subject: Refactor systemd facts (#12) * Use `Facter::Util::Resolution.exec`, which is backwards compatible with older Facter, calls the same method in modern facter * Adds basic unit testing for facts --- lib/facter/systemd.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/facter/systemd.rb b/lib/facter/systemd.rb index d488efb..4361f77 100644 --- a/lib/facter/systemd.rb +++ b/lib/facter/systemd.rb @@ -23,13 +23,13 @@ Facter.add(:systemd) do confine :kernel => :linux setcode do - Facter::Core::Execution.exec('ps -p 1 -o comm=') == 'systemd' + Facter::Util::Resolution.exec('ps -p 1 -o comm=') == 'systemd' end end Facter.add(:systemd_version) do confine :systemd => true setcode do - Facter::Core::Execution.exec("systemctl --version | awk '/systemd/{ print $2 }'") + Facter::Util::Resolution.exec("systemctl --version | awk '/systemd/{ print $2 }'") end end -- cgit v1.2.3