summaryrefslogtreecommitdiff
path: root/lib/chef/provider/service/init.rb
diff options
context:
space:
mode:
authorAJ Christensen <aj@junglist.gen.nz>2008-10-01 14:04:59 +1300
committerAJ Christensen <aj@junglist.gen.nz>2008-10-01 14:04:59 +1300
commite9ab63e8f5ab0950ba0bbd62bc41ea003c7569c2 (patch)
tree253a0da18bf2b80bd4e161e846a62bd8cea808eb /lib/chef/provider/service/init.rb
parent6b5af924ce79493d28eaaced5df5706261f6015c (diff)
downloadchef-e9ab63e8f5ab0950ba0bbd62bc41ea003c7569c2.tar.gz
Moving some stuff around. Almost functional init provider.
Diffstat (limited to 'lib/chef/provider/service/init.rb')
-rw-r--r--lib/chef/provider/service/init.rb56
1 files changed, 53 insertions, 3 deletions
diff --git a/lib/chef/provider/service/init.rb b/lib/chef/provider/service/init.rb
index 95275499f8..8e3606d515 100644
--- a/lib/chef/provider/service/init.rb
+++ b/lib/chef/provider/service/init.rb
@@ -24,15 +24,65 @@ class Chef
class Init < Chef::Provider::Service
def load_current_resource
- true
+ @current_resource = Chef::Resource::Service.new(@new_resource.name)
+ @current_resource.service_name(@new_resource.service_name)
+ running = false
+ if @new_resource.supports[:status]
+ run_command(:command => "/etc/init.d/#{@current_resource.service_name} status") == 0 ? running = true
+ elsif @new_resource.status_command
+ run_command(:command => @new_resource.status_command) == 0 ? running = true
+ else
+ unless @new_resource.pattern
+ raise Chef::Exception::Service, "#{@new_resource.service_name} does not support status (#{@new_resource.supports[:status]}) and no pattern specified"
+ end
+
+ unless Facter["ps"].value != ""
+ raise Chef::Exception::Service, "Facter could not determine how to call `ps` on your system (#{Facter["ps"].value})"
+ end
+
+ status = popen4(Facter["ps"].value) do |pid, stdin, stdout, stderr|
+ stdin.close
+ stdout.each_line do |line|
+ if @new_resource.pattern.match(line)
+ pid = line.sub(/^\s+/, '').split(/\s+/)[1]
+ end
+ end
+ end
+ unless status.exitcode == 0
+ raise Chef::Exception::Service, "Command #{Facter["ps"].value} failed"
+ else
+ pid ? running = true
+ end
+ end
+ @current_resource.running = running
+ @current_resource
end
def start_service
- run_command(:command => "/etc/init.d/#{name} start")
+ if @new_resource.start_command
+ run_command(:command => @new_resource.start_command)
+ else
+ run_command(:command => "/etc/init.d/#{name} start")
+ end
end
def stop_service
- run_command(:command => "/etc/init.d/#{name} stop")
+ if @new_resource.stop_command
+ run_command(:command => @new_resource.stop_command)
+ else
+ run_command(:command => "/etc/init.d/#{name} stop")
+ end
+ end
+
+ def restart_service
+ 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