summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/platform.rb4
-rw-r--r--lib/chef/provider/service/base.rb32
-rw-r--r--lib/chef/provider/service/debian.rb54
-rw-r--r--lib/chef/provider/service/init.rb108
4 files changed, 85 insertions, 113 deletions
diff --git a/lib/chef/platform.rb b/lib/chef/platform.rb
index 2b84da6f87..19c61b0e6b 100644
--- a/lib/chef/platform.rb
+++ b/lib/chef/platform.rb
@@ -27,7 +27,7 @@ class Chef
:ubuntu => {
:default => {
:package => Chef::Provider::Package::Apt,
- :service => Chef::Provider::Debian,
+ :service => Chef::Provider::Service::Debian,
}
},
:centos => {},
@@ -44,7 +44,7 @@ class Chef
:sysctl => Chef::Provider::Sysctl,
:execute => Chef::Provider::Execute,
:script => Chef::Provider::Script,
- :service => Chef::Provider::Init,
+ :service => Chef::Provider::Service::Init,
:perl => Chef::Provider::Script,
:python => Chef::Provider::Script,
:ruby => Chef::Provider::Script,
diff --git a/lib/chef/provider/service/base.rb b/lib/chef/provider/service/base.rb
deleted file mode 100644
index 178878296e..0000000000
--- a/lib/chef/provider/service/base.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Author:: AJ Christensen (<aj@hjksolutions.com>)
-# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# 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 File.join(File.dirname(__FILE__), "..", "service")
-require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
-
-class Chef
- class Provider
- class Base < Chef::Provider::Service
-
- def load_current_resource
- true
- end
-
- end
- end
-end
diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb
index 51597ff703..85365b124f 100644
--- a/lib/chef/provider/service/debian.rb
+++ b/lib/chef/provider/service/debian.rb
@@ -22,40 +22,42 @@ require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
class Chef
class Provider
- class Debian < Chef::Provider::Init
- def load_current_resource
- super
+ class Service
+ class Debian < Chef::Provider::Service::Init
+ def load_current_resource
+ super
- status = popen4("update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.gets(nil) =~ /etc\/rc[\dS].d\/S|not installed/i ? @current_resource.enabled(true) : @current_resource.enabled(false)
- end
+ status = popen4("update-rc.d -n -f #{@current_resource.service_name} remove") do |pid, stdin, stdout, stderr|
+ stdin.close
+ stdout.gets(nil) =~ /etc\/rc[\dS].d\/S|not installed/i ? @current_resource.enabled(true) : @current_resource.enabled(false)
+ end
- unless status.exitstatus == 0
- raise Chef::Exception::Service, "update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}"
- end
+ unless status.exitstatus == 0
+ raise Chef::Exception::Service, "update-rc.d -n -f #{@current_resource.service_name} failed - #{status.inspect}"
+ end
- @current_resource
- end
+ @current_resource
+ end
- def enable_service(name)
- run_command(:command => "update-rc.d #{name} defaults")
- end
+ def enable_service(name)
+ run_command(:command => "update-rc.d #{name} defaults")
+ end
- def disable_service(name)
- run_command(:command => "update-rc.d -f #{name} remove")
- end
+ def disable_service(name)
+ run_command(:command => "update-rc.d -f #{name} remove")
+ end
- def start_service(name)
- super
- end
+ def start_service(name)
+ super
+ end
- def stop_service(name)
- super
- end
+ def stop_service(name)
+ super
+ end
- def restart_service(name)
- super
+ def restart_service(name)
+ super
+ end
end
end
end
diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb
index 3eb70e594e..2571b8ff97 100644
--- a/lib/chef/provider/service/init.rb
+++ b/lib/chef/provider/service/init.rb
@@ -21,73 +21,75 @@ require File.join(File.dirname(__FILE__), "..", "..", "mixin", "command")
class Chef
class Provider
- class Init < Chef::Provider::Service
+ class Service
+ class Init < Chef::Provider::Service
- def load_current_resource
- @current_resource = Chef::Resource::Service.new(@new_resource.name)
- @current_resource.service_name(@new_resource.service_name)
- process_running = false
- if @new_resource.supports[:status]
- run_command(:command => "/etc/init.d/#{@current_resource.service_name} status") == 0 ? process_running = true : process_running = false
- elsif @new_resource.status_command
- run_command(:command => @new_resource.status_command) == 0 ? process_running = true : process_running = false
- else
- Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection")
- if @new_resource.pattern == @new_resource.service_name
- Chef::Log.debug("#{@new_resource} defaulting pattern to #{Regex.new(@new_resource.pattern)}")
- elsif Facter["ps"].value == ""
- raise Chef::Exception::Service, "#{@new_resource}: Facter could not determine how to call `ps` on your system (#{Facter["ps"].value})"
- end
+ def load_current_resource
+ @current_resource = Chef::Resource::Service.new(@new_resource.name)
+ @current_resource.service_name(@new_resource.service_name)
+ process_running = false
+ if @new_resource.supports[:status]
+ run_command(:command => "/etc/init.d/#{@current_resource.service_name} status") == 0 ? process_running = true : process_running = false
+ elsif @new_resource.status_command
+ run_command(:command => @new_resource.status_command) == 0 ? process_running = true : process_running = false
+ else
+ Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection")
+ if @new_resource.pattern == @new_resource.service_name
+ Chef::Log.debug("#{@new_resource} defaulting pattern to #{Regex.new(@new_resource.pattern)}")
+ elsif Facter["ps"].value == ""
+ raise Chef::Exception::Service, "#{@new_resource}: Facter could not determine how to call `ps` on your system (#{Facter["ps"].value})"
+ end
- process_pid = nil
- status = popen4(Facter["ps"].value) do |pid, stdin, stdout, stderr|
- stdin.close
- r = Regexp.new(@new_resource.pattern)
- Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
- stdout.each_line do |line|
- if r.match(line)
- process_pid = line.sub(/^\s+/, '').split(/\s+/)[1]
+ process_pid = nil
+ status = popen4(Facter["ps"].value) do |pid, stdin, stdout, stderr|
+ stdin.close
+ r = Regexp.new(@new_resource.pattern)
+ Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
+ stdout.each_line do |line|
+ if r.match(line)
+ process_pid = line.sub(/^\s+/, '').split(/\s+/)[1]
+ end
end
end
+ unless status.exitstatus == 0
+ raise Chef::Exception::Service, "Command #{Facter["ps"].value} failed"
+ else
+ process_pid ? process_running = true : process_running = false
+ Chef::Log.debug("#{@new_resource}: #{Facter["ps"].value} exited succesfully, process_running: #{process_running}")
+ end
end
- unless status.exitstatus == 0
- raise Chef::Exception::Service, "Command #{Facter["ps"].value} failed"
+ @current_resource.running process_running
+ @current_resource
+ end
+
+ def start_service(name)
+ if @new_resource.start_command
+ run_command(:command => @new_resource.start_command)
else
- process_pid ? process_running = true : process_running = false
- Chef::Log.debug("#{@new_resource}: #{Facter["ps"].value} exited succesfully, process_running: #{process_running}")
+ run_command(:command => "/etc/init.d/#{name} start")
end
end
- @current_resource.running process_running
- @current_resource
- end
- def start_service(name)
- if @new_resource.start_command
- run_command(:command => @new_resource.start_command)
- else
- run_command(:command => "/etc/init.d/#{name} start")
+ def stop_service(name)
+ if @new_resource.stop_command
+ run_command(:command => @new_resource.stop_command)
+ else
+ run_command(:command => "/etc/init.d/#{name} stop")
+ end
end
- end
- def stop_service(name)
- if @new_resource.stop_command
- run_command(:command => @new_resource.stop_command)
- else
- run_command(:command => "/etc/init.d/#{name} stop")
+ def restart_service(name)
+ if @new_resource.supports[:restart]
+ run_command(:command => "/etc/init.d/#{name} restart")
+ elsif @new_resource.restart_command
+ run_command(:command => @new_resource.restart_command)
+ else
+ stop_service
+ start_service
+ end
end
- end
- def restart_service(name)
- if @new_resource.supports[:restart]
- run_command(:command => "/etc/init.d/#{name} restart")
- elsif @new_resource.restart_command
- run_command(:command => @new_resource.restart_command)
- else
- stop_service
- start_service
- end
end
-
end
end
end