diff options
-rw-r--r-- | lib/chef/provider/service.rb | 37 | ||||
-rw-r--r-- | lib/chef/provider/service/systemd.rb | 33 | ||||
-rw-r--r-- | lib/chef/resource/service.rb | 15 | ||||
-rw-r--r-- | lib/chef/resource/systemd_service.rb | 49 |
4 files changed, 84 insertions, 50 deletions
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb index 42dfb1598a..d716e44342 100644 --- a/lib/chef/provider/service.rb +++ b/lib/chef/provider/service.rb @@ -56,9 +56,6 @@ 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 @@ -100,32 +97,6 @@ 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 @@ -195,14 +166,6 @@ class Chef raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :reload" end - def mask_service - raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :mask" - end - - def unmask_service - raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :unmask" - end - protected def default_init_command diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb index 9948d28c0f..0637251a59 100644 --- a/lib/chef/provider/service/systemd.rb +++ b/lib/chef/provider/service/systemd.rb @@ -34,6 +34,13 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:systemd) end + def load_new_resource_state + super + if ( @new_resource.masked.nil? ) + @new_resource.masked(@current_resource.masked) + end + end + def load_current_resource @current_resource = Chef::Resource::Service.new(new_resource.name) current_resource.service_name(new_resource.service_name) @@ -69,6 +76,32 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple end 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 start_service if current_resource.running Chef::Log.debug("#{new_resource} already running, not starting") diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb index 616af6cf11..849afebad0 100644 --- a/lib/chef/resource/service.rb +++ b/lib/chef/resource/service.rb @@ -24,18 +24,16 @@ class Chef class Service < Chef::Resource identity_attr :service_name - state_attrs :enabled, :running, :masked + state_attrs :enabled, :running default_action :nothing - allowed_actions :enable, :disable, :start, :stop, :restart, :reload, - :mask, :unmask + allowed_actions :enable, :disable, :start, :stop, :restart, :reload def initialize(name, run_context = nil) super @service_name = name @enabled = nil @running = nil - @masked = nil @parameters = nil @pattern = service_name @start_command = nil @@ -142,15 +140,6 @@ class Chef ) end - # if the service is masked or not - def masked(arg=nil) - set_or_return( - :masked, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - # Priority arguments can have two forms: # # - a simple number, in which the default start runlevels get diff --git a/lib/chef/resource/systemd_service.rb b/lib/chef/resource/systemd_service.rb new file mode 100644 index 0000000000..f13aa3e249 --- /dev/null +++ b/lib/chef/resource/systemd_service.rb @@ -0,0 +1,49 @@ +# +# Author:: Davide Cavalca (<dcavalca@fb.com>) +# Copyright:: Copyright (c) 2015 Facebook +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/resource/service' +require 'chef/provider/service/systemd' + +class Chef + class Resource + class SystemdService < Chef::Resource::Service + provides :service, os: "linux" do |node| + Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd) + end + + state_attrs :enabled, :running, :masked + + allowed_actions :enable, :disable, :start, :stop, :restart, :reload, + :mask, :unmask + + def initialize(name, run_context=nil) + super + @masked = nil + end + + # if the service is masked or not + def masked(arg=nil) + set_or_return( + :masked, + arg, + :kind_of => [ TrueClass, FalseClass ] + ) + end + end + end +end |