summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-02-03 14:57:22 -0800
committerGitHub <noreply@github.com>2021-02-03 14:57:22 -0800
commit3d586a3b038db3c7cba86b7393c0d3b7e0840161 (patch)
tree4cd5a124456a222938ddfc07cc6d15b70b923e6b
parentef07092cade60b92914a128a1065bc87909af465 (diff)
parente89693875cef26ba22941fd8b042dcbe758e70e3 (diff)
downloadchef-3d586a3b038db3c7cba86b7393c0d3b7e0840161.tar.gz
Merge pull request #10976 from joshuamiller01/handle_sysv_compat_case_for_systemd_service_enabled
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/service/systemd.rb5
-rw-r--r--spec/unit/provider/service/systemd_service_spec.rb22
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb
index 9b0cf3abd8..f8fac18bc3 100644
--- a/lib/chef/provider/service/systemd.rb
+++ b/lib/chef/provider/service/systemd.rb
@@ -202,6 +202,11 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
end
def is_enabled?
+ # if the service is in sysv compat mode, shellout to determine if enabled
+ if systemd_service_status["UnitFileState"] == "bad"
+ options, args = get_systemctl_options_args
+ return shell_out(systemctl_path, args, "is-enabled", new_resource.service_name, "--quiet", **options).exitstatus == 0
+ end
# See https://github.com/systemd/systemd/blob/master/src/systemctl/systemctl-is-enabled.c
# Note: enabled-runtime is excluded because this is volatile, and the state of enabled-runtime
# specifically means that the service is not enabled
diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb
index 34b8094974..ed6e3f989e 100644
--- a/spec/unit/provider/service/systemd_service_spec.rb
+++ b/spec/unit/provider/service/systemd_service_spec.rb
@@ -412,6 +412,28 @@ describe Chef::Provider::Service::Systemd do
with_systemctl_show(systemctl_path, enabled_runtime_and_active)
expect(provider.is_enabled?).to be false
end
+
+ it "should shellout to 'is-enabled' and return false if unit file is bad and sysv compat isn't enabled" do
+ bad_and_inactive = <<-STDOUT
+ ActiveState=inactive
+ UnitFileState=bad
+ STDOUT
+ with_systemctl_show(systemctl_path, bad_and_inactive)
+ systemctl_isenabled = [systemctl_path, "--system", "is-enabled", service_name, "--quiet"]
+ expect(provider).to receive(:shell_out).with(*systemctl_isenabled).and_return(shell_out_failure)
+ expect(provider.is_enabled?).to be false
+ end
+
+ it "should shellout to 'is-enabled' and return true if unit file is bad and sysv compat is enabled" do
+ bad_and_inactive = <<-STDOUT
+ ActiveState=inactive
+ UnitFileState=bad
+ STDOUT
+ with_systemctl_show(systemctl_path, bad_and_inactive)
+ systemctl_isenabled = [systemctl_path, "--system", "is-enabled", service_name, "--quiet"]
+ expect(provider).to receive(:shell_out).with(*systemctl_isenabled).and_return(shell_out_success)
+ expect(provider.is_enabled?).to be true
+ end
end
describe "is_masked?" do