def load_current_resource
@current_resource = Chef::Resource::Service.new(@new_resource.name)
@current_resource.service_name(@new_resource.service_name)
if @new_resource.status_command
Chef::Log.debug("#{@new_resource} you have specified a status command, running..")
begin
if run_command(:command => @new_resource.status_command) == 0
@current_resource.running true
end
rescue Chef::Exceptions::Exec
@current_resource.running false
nil
end
elsif @new_resource.supports[:status]
Chef::Log.debug("#{@new_resource} supports status, running")
begin
if run_command(:command => "#{@init_command} status") == 0
@current_resource.running true
end
rescue Chef::Exceptions::Exec
@current_resource.running false
nil
end
elsif
Chef::Log.debug "#{@new_resource}: falling back to process table inspection"
if ps_cmd.nil? or ps_cmd.empty?
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'command.ps' attribute"
end
status = popen4(ps_cmd) do |pid, stdin, stdout, stderr|
r = Regexp.new(@new_resource.pattern)
Chef::Log.debug "#{@new_resource}: attempting to match '#{@new_resource.pattern}' (#{r.inspect}) against process list"
stdout.each_line do |line|
if r.match(line)
@current_resource.running true
break
end
end
@current_resource.running false unless @current_resource.running
end
unless status.exitstatus == 0
raise Chef::Exceptions::Service, "Command #{ps_cmd} failed"
else
Chef::Log.debug "#{@new_resource}: running: #{@current_resource.running}"
end
end
@current_resource
end