-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add comments in init_system custom fact
- Loading branch information
Emerson Prado
committed
Sep 28, 2017
1 parent
3d5b3d7
commit d902c9b
Showing
1 changed file
with
12 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |