summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorDavide Cavalca <dcavalca@fb.com>2015-12-14 14:25:35 -0800
committerDavide Cavalca <dcavalca@fb.com>2016-02-22 14:03:16 -0800
commit11e74a822c52b57d87411f74fdc0167e2fad7d79 (patch)
tree667dfce98e211dcdfe49c98d8acdbf0fb5dff314 /lib/chef/provider
parent1967e8c24ff5990f5352cec4ae84691b1643b2e1 (diff)
downloadchef-11e74a822c52b57d87411f74fdc0167e2fad7d79.tar.gz
Extend service resource to support masking
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/service.rb29
-rw-r--r--lib/chef/provider/service/systemd.rb15
2 files changed, 44 insertions, 0 deletions
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb
index d716e44342..bb6de35d78 100644
--- a/lib/chef/provider/service.rb
+++ b/lib/chef/provider/service.rb
@@ -56,6 +56,9 @@ class Chef
if @new_resource.running.nil?
@new_resource.running(@current_resource.running)
end
+ if ( @new_resource.masked.nil? )
+ @new_resource.masked(@current_resource.masked)
+ end
end
def shared_resource_requirements
@@ -97,6 +100,32 @@ class Chef
@new_resource.enabled(false)
end
+ def action_mask
+ if @current_resource.masked
+ Chef::Log.debug("#{@new_resource} already masked - nothing to do")
+ else
+ converge_by("mask service #{@new_resource}") do
+ mask_service
+ Chef::Log.info("#{@new_resource} masked")
+ end
+ end
+ load_new_resource_state
+ @new_resource.masked(true)
+ end
+
+ def action_unmask
+ if @current_resource.masked
+ converge_by("unmask service #{@new_resource}") do
+ unmask_service
+ Chef::Log.info("#{@new_resource} masked")
+ end
+ else
+ Chef::Log.debug("#{@new_resource} already unmasked - nothing to do")
+ end
+ load_new_resource_state
+ @new_resource.masked(false)
+ end
+
def action_start
unless @current_resource.running
converge_by("start service #{@new_resource}") do
diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb
index e70576fea7..9948d28c0f 100644
--- a/lib/chef/provider/service/systemd.rb
+++ b/lib/chef/provider/service/systemd.rb
@@ -48,12 +48,14 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
@status_check_success = false
current_resource.running(false)
current_resource.enabled(false)
+ current_resource.masked(false)
end
else
current_resource.running(is_active?)
end
current_resource.enabled(is_enabled?)
+ current_resource.masked(is_masked?)
current_resource
end
@@ -119,6 +121,14 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
shell_out!("#{systemctl_path} disable #{new_resource.service_name}")
end
+ def mask_service
+ shell_out!("#{systemctl_path} mask #{new_resource.service_name}")
+ end
+
+ def unmask_service
+ shell_out!("#{systemctl_path} unmask #{new_resource.service_name}")
+ end
+
def is_active?
shell_out("#{systemctl_path} is-active #{new_resource.service_name} --quiet").exitstatus == 0
end
@@ -127,6 +137,11 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
shell_out("#{systemctl_path} is-enabled #{new_resource.service_name} --quiet").exitstatus == 0
end
+ def is_masked?
+ s = shell_out("#{systemctl_path} is-enabled #{new_resource.service_name}")
+ s..exitstatus != 0 && s.stdout.include?('masked', 'masked-runtime')
+ end
+
private
def systemctl_path