summaryrefslogtreecommitdiff
path: root/lib/chef/provider/service
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-10-24 10:45:43 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-10-24 10:45:43 -0700
commit97aaf5bbcdfd0810722b123bdc67e883a7ca8077 (patch)
tree25663bf1d4f53664b96844251091b51273ad84c7 /lib/chef/provider/service
parentcb1bcb1f08816f551f96e713624718f58da3c9b3 (diff)
downloadchef-97aaf5bbcdfd0810722b123bdc67e883a7ca8077.tar.gz
Chef-12 RC Provider Resolver
makes resource and provider class resolution more dynamic. begins deprecation of Chef::Platform static mapping.
Diffstat (limited to 'lib/chef/provider/service')
-rw-r--r--lib/chef/provider/service/arch.rb6
-rw-r--r--lib/chef/provider/service/debian.rb64
-rw-r--r--lib/chef/provider/service/freebsd.rb5
-rw-r--r--lib/chef/provider/service/gentoo.rb3
-rw-r--r--lib/chef/provider/service/init.rb2
-rw-r--r--lib/chef/provider/service/insserv.rb22
-rw-r--r--lib/chef/provider/service/invokercd.rb6
-rw-r--r--lib/chef/provider/service/macosx.rb2
-rw-r--r--lib/chef/provider/service/redhat.rb12
-rw-r--r--lib/chef/provider/service/simple.rb2
-rw-r--r--lib/chef/provider/service/solaris.rb2
-rw-r--r--lib/chef/provider/service/systemd.rb7
-rw-r--r--lib/chef/provider/service/upstart.rb7
-rw-r--r--lib/chef/provider/service/windows.rb4
14 files changed, 102 insertions, 42 deletions
diff --git a/lib/chef/provider/service/arch.rb b/lib/chef/provider/service/arch.rb
index 9be5fb6fe3..888fb3fdf5 100644
--- a/lib/chef/provider/service/arch.rb
+++ b/lib/chef/provider/service/arch.rb
@@ -20,6 +20,12 @@ require 'chef/provider/service/init'
class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
+ provides :service, platform_family: "arch"
+
+ def self.supports?(resource, action)
+ ::File.exist?("/etc/rc.d/#{resource.service_name}")
+ end
+
def initialize(new_resource, run_context)
super
@init_command = "/etc/rc.d/#{@new_resource.service_name}"
diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb
index 1ebef90349..25b1960b26 100644
--- a/lib/chef/provider/service/debian.rb
+++ b/lib/chef/provider/service/debian.rb
@@ -25,13 +25,19 @@ class Chef
UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i
UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i
+ provides :service, platform_family: "debian"
+
+ def self.supports?(resource, action)
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian)
+ end
+
def load_current_resource
super
@priority_success = true
@rcd_status = nil
- @current_resource.priority(get_priority)
- @current_resource.enabled(service_currently_enabled?(@current_resource.priority))
- @current_resource
+ current_resource.priority(get_priority)
+ current_resource.enabled(service_currently_enabled?(current_resource.priority))
+ current_resource
end
def define_resource_requirements
@@ -47,7 +53,7 @@ class Chef
requirements.assert(:all_actions) do |a|
a.assertion { @priority_success }
- a.failure_message Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} failed - #{@rcd_status.inspect}"
+ a.failure_message Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{current_resource.service_name} failed - #{@rcd_status.inspect}"
# This can happen if the service is not yet installed,so we'll fake it.
a.whyrun ["Unable to determine priority of service, assuming service would have been correctly installed earlier in the run.",
"Assigning temporary priorities to continue.",
@@ -59,7 +65,7 @@ class Chef
"3"=>[:start, "20"],
"4"=>[:start, "20"],
"5"=>[:start, "20"]}
- @current_resource.priority(temp_priorities)
+ current_resource.priority(temp_priorities)
end
end
end
@@ -67,7 +73,7 @@ class Chef
def get_priority
priority = {}
- @rcd_status = popen4("/usr/sbin/update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
+ @rcd_status = popen4("/usr/sbin/update-rc.d -n -f #{current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
[stdout, stderr].each do |iop|
iop.each_line do |line|
@@ -99,7 +105,7 @@ class Chef
def service_currently_enabled?(priority)
enabled = false
priority.each { |runlevel, arguments|
- Chef::Log.debug("#{@new_resource} runlevel #{runlevel}, action #{arguments[0]}, priority #{arguments[1]}")
+ Chef::Log.debug("#{new_resource} runlevel #{runlevel}, action #{arguments[0]}, priority #{arguments[1]}")
# if we are in a update-rc.d default startup runlevel && we start in this runlevel
if %w[ 1 2 3 4 5 S ].include?(runlevel) && arguments[0] == :start
enabled = true
@@ -111,63 +117,63 @@ class Chef
# Override method from parent to ensure priority is up-to-date
def action_enable
- if @new_resource.priority.nil?
+ if new_resource.priority.nil?
priority_ok = true
else
- priority_ok = @current_resource.priority == @new_resource.priority
+ priority_ok = @current_resource.priority == new_resource.priority
end
- if @current_resource.enabled and priority_ok
- Chef::Log.debug("#{@new_resource} already enabled - nothing to do")
+ if current_resource.enabled and priority_ok
+ Chef::Log.debug("#{new_resource} already enabled - nothing to do")
else
- converge_by("enable service #{@new_resource}") do
+ converge_by("enable service #{new_resource}") do
enable_service
- Chef::Log.info("#{@new_resource} enabled")
+ Chef::Log.info("#{new_resource} enabled")
end
end
load_new_resource_state
- @new_resource.enabled(true)
+ new_resource.enabled(true)
end
def enable_service
- if @new_resource.priority.is_a? Integer
- shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
- shell_out!("/usr/sbin/update-rc.d #{@new_resource.service_name} defaults #{@new_resource.priority} #{100 - @new_resource.priority}")
- elsif @new_resource.priority.is_a? Hash
+ if new_resource.priority.is_a? Integer
+ shell_out!("/usr/sbin/update-rc.d -f #{new_resource.service_name} remove")
+ shell_out!("/usr/sbin/update-rc.d #{new_resource.service_name} defaults #{new_resource.priority} #{100 - new_resource.priority}")
+ elsif new_resource.priority.is_a? Hash
# we call the same command regardless of we're enabling or disabling
# users passing a Hash are responsible for setting their own start priorities
set_priority
else # No priority, go with update-rc.d defaults
- shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
- shell_out!("/usr/sbin/update-rc.d #{@new_resource.service_name} defaults")
+ shell_out!("/usr/sbin/update-rc.d -f #{new_resource.service_name} remove")
+ shell_out!("/usr/sbin/update-rc.d #{new_resource.service_name} defaults")
end
end
def disable_service
- if @new_resource.priority.is_a? Integer
+ if new_resource.priority.is_a? Integer
# Stop processes in reverse order of start using '100 - start_priority'
- shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
- shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop #{100 - @new_resource.priority} 2 3 4 5 .")
- elsif @new_resource.priority.is_a? Hash
+ shell_out!("/usr/sbin/update-rc.d -f #{new_resource.service_name} remove")
+ shell_out!("/usr/sbin/update-rc.d -f #{new_resource.service_name} stop #{100 - new_resource.priority} 2 3 4 5 .")
+ elsif new_resource.priority.is_a? Hash
# we call the same command regardless of we're enabling or disabling
# users passing a Hash are responsible for setting their own stop priorities
set_priority
else
# no priority, using '100 - 20 (update-rc.d default)' to stop in reverse order of start
- shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
- shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} stop 80 2 3 4 5 .")
+ shell_out!("/usr/sbin/update-rc.d -f #{new_resource.service_name} remove")
+ shell_out!("/usr/sbin/update-rc.d -f #{new_resource.service_name} stop 80 2 3 4 5 .")
end
end
def set_priority
args = ""
- @new_resource.priority.each do |level, o|
+ new_resource.priority.each do |level, o|
action = o[0]
priority = o[1]
args += "#{action} #{priority} #{level} . "
end
- shell_out!("/usr/sbin/update-rc.d -f #{@new_resource.service_name} remove")
- shell_out!("/usr/sbin/update-rc.d #{@new_resource.service_name} #{args}")
+ shell_out!("/usr/sbin/update-rc.d -f #{new_resource.service_name} remove")
+ shell_out!("/usr/sbin/update-rc.d #{new_resource.service_name} #{args}")
end
end
end
diff --git a/lib/chef/provider/service/freebsd.rb b/lib/chef/provider/service/freebsd.rb
index e0d9696f61..e4a456ac25 100644
--- a/lib/chef/provider/service/freebsd.rb
+++ b/lib/chef/provider/service/freebsd.rb
@@ -27,8 +27,9 @@ class Chef
attr_reader :enabled_state_found
- implements :service,
- :on_platforms => [:freebsd, :netbsd]
+ provides :service, os: [ "freebsd", "netbsd" ]
+
+ include Chef::Mixin::ShellOut
def initialize(new_resource, run_context)
super
diff --git a/lib/chef/provider/service/gentoo.rb b/lib/chef/provider/service/gentoo.rb
index e2dff10994..3dab920f06 100644
--- a/lib/chef/provider/service/gentoo.rb
+++ b/lib/chef/provider/service/gentoo.rb
@@ -22,6 +22,9 @@ require 'chef/mixin/command'
require 'chef/util/path_helper'
class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
+
+ provides :service, platform_family: "gentoo"
+
def load_current_resource
@new_resource.supports[:status] = true
diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb
index 5d8bb5bb38..ab40a720f6 100644
--- a/lib/chef/provider/service/init.rb
+++ b/lib/chef/provider/service/init.rb
@@ -26,6 +26,8 @@ class Chef
attr_accessor :init_command
+ provides :service, os: "!windows"
+
def initialize(new_resource, run_context)
super
@init_command = "/etc/init.d/#{@new_resource.service_name}"
diff --git a/lib/chef/provider/service/insserv.rb b/lib/chef/provider/service/insserv.rb
index 1ee817707a..df5a162a45 100644
--- a/lib/chef/provider/service/insserv.rb
+++ b/lib/chef/provider/service/insserv.rb
@@ -24,26 +24,32 @@ class Chef
class Service
class Insserv < Chef::Provider::Service::Init
+ provides :service, os: "linux"
+
+ def self.supports?(resource, action)
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv)
+ end
+
def load_current_resource
super
- # Look for a /etc/rc.*/SnnSERVICE link to signifiy that the service would be started in a runlevel
- if Dir.glob("/etc/rc**/S*#{Chef::Util::PathHelper.escape_glob(@current_resource.service_name)}").empty?
- @current_resource.enabled false
+ # Look for a /etc/rc.*/SnnSERVICE link to signify that the service would be started in a runlevel
+ if Dir.glob("/etc/rc**/S*#{Chef::Util::PathHelper.escape_glob(current_resource.service_name)}").empty?
+ current_resource.enabled false
else
- @current_resource.enabled true
+ current_resource.enabled true
end
- @current_resource
+ current_resource
end
def enable_service()
- shell_out!("/sbin/insserv -r -f #{@new_resource.service_name}")
- shell_out!("/sbin/insserv -d -f #{@new_resource.service_name}")
+ shell_out!("/sbin/insserv -r -f #{new_resource.service_name}")
+ shell_out!("/sbin/insserv -d -f #{new_resource.service_name}")
end
def disable_service()
- shell_out!("/sbin/insserv -r -f #{@new_resource.service_name}")
+ shell_out!("/sbin/insserv -r -f #{new_resource.service_name}")
end
end
end
diff --git a/lib/chef/provider/service/invokercd.rb b/lib/chef/provider/service/invokercd.rb
index e6afa7272a..c7472211bc 100644
--- a/lib/chef/provider/service/invokercd.rb
+++ b/lib/chef/provider/service/invokercd.rb
@@ -23,6 +23,12 @@ class Chef
class Service
class Invokercd < Chef::Provider::Service::Init
+ provides :service, platform_family: "debian"
+
+ def self.supports?(resource, action)
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokerc)
+ end
+
def initialize(new_resource, run_context)
super
@init_command = "/usr/sbin/invoke-rc.d #{@new_resource.service_name}"
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb
index ad1535327b..10ad1aa29d 100644
--- a/lib/chef/provider/service/macosx.rb
+++ b/lib/chef/provider/service/macosx.rb
@@ -26,6 +26,8 @@ class Chef
class Service
class Macosx < Chef::Provider::Service::Simple
+ provides :service, os: "darwin"
+
def self.gather_plist_dirs
locations = %w{/Library/LaunchAgents
/Library/LaunchDaemons
diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb
index 7a7b2a1c40..90744ae268 100644
--- a/lib/chef/provider/service/redhat.rb
+++ b/lib/chef/provider/service/redhat.rb
@@ -26,11 +26,17 @@ class Chef
CHKCONFIG_ON = /\d:on/
CHKCONFIG_MISSING = /No such/
+ provides :service, platform_family: [ "rhel", "fedora", "suse" ]
+
+ def self.supports?(resource, action)
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat)
+ end
+
def initialize(new_resource, run_context)
super
- @init_command = "/sbin/service #{@new_resource.service_name}"
- @new_resource.supports[:status] = true
- @service_missing = false
+ @init_command = "/sbin/service #{@new_resource.service_name}"
+ @new_resource.supports[:status] = true
+ @service_missing = false
end
def define_resource_requirements
diff --git a/lib/chef/provider/service/simple.rb b/lib/chef/provider/service/simple.rb
index bd51d15f84..ee403ee163 100644
--- a/lib/chef/provider/service/simple.rb
+++ b/lib/chef/provider/service/simple.rb
@@ -25,6 +25,8 @@ class Chef
class Service
class Simple < Chef::Provider::Service
+ # this must be subclassed to be useful so does not directly implement :service
+
attr_reader :status_load_success
def load_current_resource
diff --git a/lib/chef/provider/service/solaris.rb b/lib/chef/provider/service/solaris.rb
index f0584dcf6d..eaea6bb1ab 100644
--- a/lib/chef/provider/service/solaris.rb
+++ b/lib/chef/provider/service/solaris.rb
@@ -26,6 +26,8 @@ class Chef
class Solaris < Chef::Provider::Service
attr_reader :maintenance
+ provides :service, os: "solaris2"
+
def initialize(new_resource, run_context=nil)
super
@init_command = "/usr/sbin/svcadm"
diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb
index 31feee65d4..311751ab9a 100644
--- a/lib/chef/provider/service/systemd.rb
+++ b/lib/chef/provider/service/systemd.rb
@@ -20,6 +20,13 @@ require 'chef/resource/service'
require 'chef/provider/service/simple'
class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
+
+ provides :service, os: "linux"
+
+ def self.supports?(resource, action)
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
+ end
+
def load_current_resource
@current_resource = Chef::Resource::Service.new(@new_resource.name)
@current_resource.service_name(@new_resource.service_name)
diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb
index 670bf9e5f8..41bd850d6a 100644
--- a/lib/chef/provider/service/upstart.rb
+++ b/lib/chef/provider/service/upstart.rb
@@ -27,6 +27,13 @@ class Chef
class Upstart < Chef::Provider::Service::Simple
UPSTART_STATE_FORMAT = /\w+ \(?(\w+)\)?[\/ ](\w+)/
+ provides :service, os: "linux"
+
+ def self.supports?(resource, action)
+ Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) &&
+ Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:upstart)
+ end
+
# Upstart does more than start or stop a service, creating multiple 'states' [1] that a service can be in.
# In chef, when we ask a service to start, we expect it to have started before performing the next step
# since we have top down dependencies. Which is to say we may follow witha resource next that requires
diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb
index d31aad4c9d..4b1d2079ec 100644
--- a/lib/chef/provider/service/windows.rb
+++ b/lib/chef/provider/service/windows.rb
@@ -25,6 +25,10 @@ end
class Chef::Provider::Service::Windows < Chef::Provider::Service
+ provides :service, os: "windows"
+
+ include Chef::Mixin::ShellOut
+
#Win32::Service.get_start_type
AUTO_START = 'auto start'
MANUAL = 'demand start'