Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions lib/puppet/provider/service/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,6 @@ def disable
systemctl_change_enable(:disable)
end

def get_start_link_count
# Start links don't include '.service'. Just search for the service name.
if @resource[:name] =~ /\.service/
link_name = @resource[:name].split('.')[0]
else
link_name = @resource[:name]
end

Dir.glob("/etc/rc*.d/S??#{link_name}").length
end

def cached_enabled?
return @cached_enabled if @cached_enabled

Expand All @@ -118,39 +107,9 @@ def enabled?
return :false if output == 'indirect'
return :true if code == 0

if output.empty? && (code > 0) && Puppet.runtime[:facter].value('os.family').casecmp('debian').zero?
ret = debian_enabled?
return ret if ret
end

:false
end

# This method is required for Debian systems due to the way the SysVInit-Systemd
# compatibility layer works. When we are trying to manage a service which does not
# have a Systemd unit file, we need to go through the old init script to determine
# whether it is enabled or not. See PUP-5016 for more details.
#
def debian_enabled?
status = execute(["/usr/sbin/invoke-rc.d", "--quiet", "--query", @resource[:name], "start"], :failonfail => false)
if [104, 106].include?(status.exitstatus)
:true
elsif [101, 105].include?(status.exitstatus)
# 101 is action not allowed, which means we have to do the check manually.
# 105 is unknown, which generally means the initscript does not support query
# The debian policy states that the initscript should support methods of query
# For those that do not, perform the checks manually
# http://www.debian.org/doc/debian-policy/ch-opersys.html
if get_start_link_count >= 4
:true
else
:false
end
else
:false
end
end

# Define the daemon_reload? function to check if the unit is requiring to trigger a "systemctl daemon-reload"
# If the unit file is flagged with NeedDaemonReload=yes, then a systemd daemon-reload will be run.
# If multiple unit files have been updated, the first one flagged will trigger the daemon-reload for all of them.
Expand Down
45 changes: 2 additions & 43 deletions spec/unit/provider/service/systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,12 @@
expect(provider.enabled?).to eq(:mask)
end

it "should consider nonexistent services to be disabled" do
it "should consider nonexistent services to be disabled and not fall back to the Debian SysVInit invoke-rc.d probe" do
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'doesnotexist'))
allow(Facter).to receive(:value).with('os.family').and_return('debian')
expect(provider).to receive(:execute).with(['/bin/systemctl','is-enabled', '--', 'doesnotexist'], {:failonfail => false})
.and_return(Puppet::Util::Execution::ProcessOutput.new("", 1))
expect(provider).to receive(:execute).with(["/usr/sbin/invoke-rc.d", "--quiet", "--query", "doesnotexist", "start"], {:failonfail => false})
.and_return(Puppet::Util::Execution::ProcessOutput.new("", 1))
expect(provider).not_to receive(:execute).with(["/usr/sbin/invoke-rc.d", "--quiet", "--query", "doesnotexist", "start"], {:failonfail => false})

expect(provider.enabled?).to be(:false)
end
Expand Down Expand Up @@ -457,32 +456,6 @@
end
end

describe "#debian_enabled?" do
[104, 106].each do |status|
it "should return true when invoke-rc.d returns #{status}" do
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
allow(provider).to receive(:execute).and_return(Puppet::Util::Execution::ProcessOutput.new('', status))
expect(provider.debian_enabled?).to eq(:true)
end
end

[101, 105].each do |status|
it "should return true when status is #{status} and there are at least 4 start links" do
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
allow(provider).to receive(:execute).and_return(Puppet::Util::Execution::ProcessOutput.new('', status))
expect(provider).to receive(:get_start_link_count).and_return(4)
expect(provider.debian_enabled?).to eq(:true)
end

it "should return false when status is #{status} and there are less than 4 start links" do
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
allow(provider).to receive(:execute).and_return(Puppet::Util::Execution::ProcessOutput.new('', status))
expect(provider).to receive(:get_start_link_count).and_return(1)
expect(provider.debian_enabled?).to eq(:false)
end
end
end

describe "#insync_enabled?" do
let(:provider) do
provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service', :enable => false))
Expand Down Expand Up @@ -566,20 +539,6 @@
end
end

describe "#get_start_link_count" do
it "should strip the '.service' from the search if present in the resource name" do
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
expect(Dir).to receive(:glob).with("/etc/rc*.d/S??sshd").and_return(['files'])
provider.get_start_link_count
end

it "should use the full service name if it does not include '.service'" do
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd'))
expect(Dir).to receive(:glob).with("/etc/rc*.d/S??sshd").and_return(['files'])
provider.get_start_link_count
end
end

it "(#16451) has command systemctl without being fully qualified" do
expect(provider_class.instance_variable_get(:@commands)).to include(:systemctl => 'systemctl')
end
Expand Down