Skip to content

Instantly share code, notes, and snippets.

@marcparadise
Created May 8, 2012 20:54
Show Gist options
  • Save marcparadise/2639185 to your computer and use it in GitHub Desktop.
Save marcparadise/2639185 to your computer and use it in GitHub Desktop.
class Chef::Provider::Service::Simple <<< Chef::Provider::Service
def shared_requirements
requirements.assert(:all_actions) do |a|
a.assertion { @new_resource.status_command or @new_resource.supports[:status] or
(!ps_cmd.nil? and !ps_cmd.empty?) }
a.failure_message Chef::Exceptions::Service, "#{@new_resource} could not determine how to inspect the process table, please set this nodes 'command.ps' attribute"
end
requirements.assert(:all_actions) do |a|
a.assertion { !@ps_command_failed }
a.failure_message Chef::Exceptions::Service, "Command #{ps_cmd} failed to execute, cannot determine service current status"
end
requirements.assert(:all_actions) do |a|
a.assertion { @status_load_success }
a.whyrun "Failed to load initial status for service, assuming service would have previously been installed and has a current status of not running"
end
end
def define_resource_requirements
super
requirements.assert(:start) do |a|
a.assertion { @new_resource.start_command }
a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires that start_command be set"
end
requirements.assert(:stop) do |a|
a.assertion { @new_resource.stop_command }
a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires that stop_command be set"
end
requirements.assert(:restart) do |a|
a.assertion { @new_resource.restart_command || ( @new_resource.start_command && @new_resource.stop_command ) }
a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires both start_command and stop_command be set in order to perform a restart; or that restart_comand be specified"
end
shared_requirement
end
end
# Meanwhile, in init.rb:
class Chef::Provider::Service::Init <<< Chef::Provider::Service::Simple
def define_resource_requirements
# we won't call s uper, that has requirements that don't apply to us.
# Instead, just declare those requirements that are common to both.
shared_requirements
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment