Skip to content

Commit

Permalink
(PUP-7312) Confine systemd provider to /lib/systemd/system
Browse files Browse the repository at this point in the history
/run/systemd/system does not exist when running Puppet in a chroot environment
/lib/systemd/system is always available irregardless of the environment
  • Loading branch information
arioch authored and mihaibuzgau committed Jul 23, 2019
1 parent 857c814 commit a7b9d0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/puppet/provider/service/systemd.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Manage systemd services using systemctl

require 'puppet/file_system'

Puppet::Type.type(:service).provide :systemd, :parent => :base do
desc "Manages `systemd` services using `systemctl`.
Expand All @@ -9,14 +11,7 @@

commands :systemctl => "systemctl"

if Facter.value(:osfamily).downcase == 'debian'
# With multiple init systems on Debian, it is possible to have
# pieces of systemd around (e.g. systemctl) but not really be
# using systemd. We do not do this on other platforms as it can
# cause issues when running in a chroot without /run mounted
# (PUP-5577)
confine :exists => "/run/systemd/system"
end
confine :true => Puppet::FileSystem.exist?('/proc/1/exe') && Puppet::FileSystem.readlink('/proc/1/exe').include?('systemd')

defaultfor :osfamily => [:archlinux]
defaultfor :osfamily => :redhat, :operatingsystemmajrelease => ["7", "8"]
Expand Down
5 changes: 5 additions & 0 deletions spec/integration/provider/service/systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
expect(described_class).to be_suitable
end

it "should be considered suitable if /proc/1/exe is present and contains 'systemd'",
:if => File.exist?('/proc/1/exe') && File.open('/proc/1/exe').grep(/systemd/).size > 0
expect(provider_class).to be_suitable
end

it "should not be cosidered suitable if systemctl is absent",
:unless => (File.executable?('/bin/systemctl') or File.executable?('/usr/bin/systemctl')) do
expect(described_class).not_to be_suitable
Expand Down

0 comments on commit a7b9d0e

Please sign in to comment.