Skip to content

Commit

Permalink
(PUP-11433) Use systemd by default in CentOS/RHEL
Browse files Browse the repository at this point in the history
Since CentOS7/RHEL7, systemd is used to manage services. This change
changes the default provider in CentOS/RHEL from the old redhat
provider based on init, to the systemd provider, so that we no longer
need to update the provider code when adding support for a new version
of CentOS/RHEL.

The old redhat provider is still used for CentOS/RHEL<7 which are using
init to manage services.
  • Loading branch information
kajinamit committed Jan 24, 2022
1 parent 389dbf6 commit 95d3215
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/puppet/provider/service/redhat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

commands :chkconfig => "/sbin/chkconfig", :service => "/sbin/service"

defaultfor :osfamily => :redhat
defaultfor :osfamily => :redhat, :operatingsystemmajrelease => (4..6).to_a
defaultfor :operatingsystem => :amazon, :operatingsystemmajrelease => ["2017"]
defaultfor :osfamily => :suse, :operatingsystemmajrelease => ["10", "11"]

# Remove the symlinks
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet/provider/service/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
confine :true => Puppet::FileSystem.exist?('/proc/1/comm') && Puppet::FileSystem.read('/proc/1/comm').include?('systemd')

defaultfor :osfamily => [:archlinux]
defaultfor :osfamily => :redhat, :operatingsystemmajrelease => ["7", "8", "9"]
defaultfor :osfamily => :redhat
notdefaultfor :osfamily => :redhat, :operatingsystemmajrelease => (4..6).to_a
defaultfor :osfamily => :redhat, :operatingsystem => :fedora
defaultfor :osfamily => :suse
defaultfor :osfamily => :coreos
defaultfor :operatingsystem => :amazon, :operatingsystemmajrelease => ["2"]
notdefaultfor :operatingsystem => :amazon, :operatingsystemmajrelease => ["2017"]
defaultfor :operatingsystem => :debian
notdefaultfor :operatingsystem => :debian, :operatingsystemmajrelease => ["5", "6", "7"] # These are using the "debian" method
defaultfor :operatingsystem => :LinuxMint
Expand Down
8 changes: 3 additions & 5 deletions spec/unit/provider/service/redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
allow(Facter).to receive(:value).with(:osfamily).and_return('RedHat')
end

osfamilies = [ 'RedHat' ]

osfamilies.each do |osfamily|
it "should be the default provider on #{osfamily}" do
expect(Facter).to receive(:value).with(:osfamily).and_return(osfamily)
[4, 5, 6].each do |ver|
it "should be the default provider on rhel#{ver}" do
allow(Facter).to receive(:value).with(:operatingsystemmajrelease).and_return(ver)
expect(provider_class.default?).to be_truthy
end
end
Expand Down

0 comments on commit 95d3215

Please sign in to comment.