summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/service.rb38
-rw-r--r--lib/chef/provider/service/systemd.rb34
-rw-r--r--lib/chef/resource/service.rb15
-rw-r--r--lib/chef/resource/systemd_service.rb49
-rw-r--r--spec/unit/provider/service/systemd_service_spec.rb3
5 files changed, 54 insertions, 85 deletions
diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb
index d716e44342..b848d33083 100644
--- a/lib/chef/provider/service.rb
+++ b/lib/chef/provider/service.rb
@@ -1,5 +1,6 @@
#
# Author:: AJ Christensen (<aj@hjksolutions.com>)
+# Author:: Davide Cavalca (<dcavalca@fb.com>)
# Copyright:: Copyright 2008-2016, Chef Software, Inc.
# License:: Apache License, Version 2.0
#
@@ -56,6 +57,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 +101,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} unmasked")
+ 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
@@ -150,6 +180,14 @@ class Chef
raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :disable"
end
+ def mask_service
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :mask"
+ end
+
+ def unmask_service
+ raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :unmask"
+ end
+
def start_service
raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :start"
end
diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb
index 0637251a59..e96c580fdd 100644
--- a/lib/chef/provider/service/systemd.rb
+++ b/lib/chef/provider/service/systemd.rb
@@ -1,5 +1,6 @@
#
# Author:: Stephen Haynes (<sh@nomitor.com>)
+# Author:: Davide Cavalca (<dcavalca@fb.com>)
# Copyright:: Copyright 2011-2016, Chef Software Inc.
# License:: Apache License, Version 2.0
#
@@ -34,13 +35,6 @@ 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)
@@ -76,32 +70,6 @@ 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 849afebad0..860d5b05ff 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -24,16 +24,18 @@ class Chef
class Service < Chef::Resource
identity_attr :service_name
- state_attrs :enabled, :running
+ state_attrs :enabled, :running, :masked
default_action :nothing
- allowed_actions :enable, :disable, :start, :stop, :restart, :reload
+ allowed_actions :enable, :disable, :start, :stop, :restart, :reload,
+ :mask, :unmask
def initialize(name, run_context = nil)
super
@service_name = name
@enabled = nil
@running = nil
+ @masked = nil
@parameters = nil
@pattern = service_name
@start_command = nil
@@ -140,6 +142,15 @@ 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
deleted file mode 100644
index f13aa3e249..0000000000
--- a/lib/chef/resource/systemd_service.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# 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
diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb
index cb2a15faf9..8923437515 100644
--- a/spec/unit/provider/service/systemd_service_spec.rb
+++ b/spec/unit/provider/service/systemd_service_spec.rb
@@ -1,5 +1,6 @@
#
# Author:: Stephen Haynes (<sh@nomitor.com>)
+# Author:: Davide Cavalca (<dcavalca@fb.com>)
# Copyright:: Copyright 2011-2016, Chef Software Inc.
# License:: Apache License, Version 2.0
#
@@ -28,7 +29,7 @@ describe Chef::Provider::Service::Systemd do
let(:service_name) { "rsyslog.service" }
- let(:new_resource) { Chef::Resource::SystemdService.new(service_name) }
+ let(:new_resource) { Chef::Resource::Service.new(service_name) }
let(:provider) { Chef::Provider::Service::Systemd.new(new_resource, run_context) }