Class: Chef::Provider::Service::Redhat
- Inherits:
-
Init
- Object
- Chef::Provider
- Chef::Provider::Service
- Simple
- Init
- Chef::Provider::Service::Redhat
- Defined in:
- lib/chef/provider/service/redhat.rb
Constant Summary collapse
- CHKCONFIG_ON =
/\d:on/
- CHKCONFIG_MISSING =
/No such/
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary
Attributes inherited from Init
Attributes inherited from Simple
Attributes inherited from Chef::Provider
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Class Method Summary collapse
Instance Method Summary collapse
- #define_resource_requirements ⇒ Object
- #disable_service ⇒ Object
- #enable_service ⇒ Object
-
#initialize(new_resource, run_context) ⇒ Redhat
constructor
A new instance of Redhat.
- #load_current_resource ⇒ Object
Methods inherited from Init
#reload_service, #restart_service, #start_service, #stop_service
Methods inherited from Simple
#reload_service, #restart_service, #shared_resource_requirements, #start_service, #stop_service, #whyrun_supported?
Methods inherited from Chef::Provider::Service
#action_disable, #action_enable, #action_reload, #action_restart, #action_start, #action_stop, #load_new_resource_state, #reload_service, #restart_service, #shared_resource_requirements, #start_service, #stop_service, #whyrun_supported?
Methods included from Mixin::Command
#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_and_return_stdout_stderr, #run_command_with_systems_locale
Methods included from Mixin::Command::Windows
Methods included from Mixin::Command::Unix
Methods inherited from Chef::Provider
#action_nothing, #cleanup_after_converge, #converge_by, #events, #node, node_map, #process_resource_requirements, provides, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Constructor Details
#initialize(new_resource, run_context) ⇒ Redhat
Returns a new instance of Redhat.
39 40 41 42 43 44 |
# File 'lib/chef/provider/service/redhat.rb', line 39 def initialize(new_resource, run_context) super @init_command = "/sbin/service #{@new_resource.service_name}" @new_resource.supports[:status] = true @service_missing = false end |
Class Method Details
.provides?(node, resource) ⇒ Boolean
31 32 33 |
# File 'lib/chef/provider/service/redhat.rb', line 31 def self.provides?(node, resource) super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat) end |
.supports?(resource, action) ⇒ Boolean
35 36 37 |
# File 'lib/chef/provider/service/redhat.rb', line 35 def self.supports?(resource, action) Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) end |
Instance Method Details
#define_resource_requirements ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/provider/service/redhat.rb', line 46 def define_resource_requirements shared_resource_requirements requirements.assert(:all_actions) do |a| chkconfig_file = "/sbin/chkconfig" a.assertion { ::File.exists? chkconfig_file } a. Chef::Exceptions::Service, "#{chkconfig_file} does not exist!" end requirements.assert(:start, :enable, :reload, :restart) do |a| a.assertion { !@service_missing } a. Chef::Exceptions::Service, "#{@new_resource}: unable to locate the init.d script!" a.whyrun "Assuming service would be disabled. The init script is not presently installed." end end |
#disable_service ⇒ Object
78 79 80 |
# File 'lib/chef/provider/service/redhat.rb', line 78 def disable_service() shell_out! "/sbin/chkconfig #{@new_resource.service_name} off" end |
#enable_service ⇒ Object
74 75 76 |
# File 'lib/chef/provider/service/redhat.rb', line 74 def enable_service() shell_out! "/sbin/chkconfig #{@new_resource.service_name} on" end |
#load_current_resource ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chef/provider/service/redhat.rb', line 62 def load_current_resource super if ::File.exists?("/sbin/chkconfig") chkconfig = shell_out!("/sbin/chkconfig --list #{@current_resource.service_name}", :returns => [0,1]) @current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON)) @service_missing = !!(chkconfig.stderr =~ CHKCONFIG_MISSING) end @current_resource end |