Skip to content

Commit

Permalink
Add comments in init_system custom fact
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerson Prado committed Sep 28, 2017
1 parent 3d5b3d7 commit d902c9b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/facter/init_system.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
Facter.add(:init_system) do
confine :kernel => 'Linux'
setcode do

# Active init system process has PID 1
proc_1 = Facter::Core::Execution::exec('ps --no-headers -p 1').split(' ')[-1]

# A PID 1 process called `init` can be a link to systemd or upstart
unless proc_1 == 'init'
proc_1
else
path_exec = Facter::Core::Execution::exec("ls -l $(which #{proc_1})").split(' ')[-1]
file_exec = path_exec.split('/')[-1]

# An executable called `init` can be a link to systemd or upstart
unless file_exec == 'init'
file_exec
else

# Check package which provided running init system executable
case Facter.value(:osfamily)
when 'Debian', 'Ubuntu'
pkg_exec = Facter::Core::Execution::exec("dpkg-query -S #{path_exec}").split(' ')[0]
when 'RedHat'
pkg_exec = Facter::Core::Execution::exec("rpm -qf #{path_exec}").split('-')[0]
# TODO: add similar checks for other distros
else
pkg_exec = 'unknown'
end
pkg_exec.downcase[/systemd|upstart|init|unknown/]

end

end

end
end

0 comments on commit d902c9b

Please sign in to comment.