Class: Chef::Provider::Service::Redhat

Inherits:
Init show all
Includes:
Mixin::ShellOut
Defined in:
lib/chef/provider/service/redhat.rb

Constant Summary

CHKCONFIG_ON =
/\d:on/

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods included from Mixin::ShellOut

#shell_out, #shell_out!

Methods inherited from Init

#reload_service, #restart_service, #start_service, #stop_service

Methods inherited from Simple

#ps_cmd, #reload_service, #restart_service, #start_service, #stop_service

Methods inherited from Chef::Provider::Service

#action_disable, #action_enable, #action_reload, #action_restart, #action_start, #action_stop, #reload_service, #restart_service, #start_service, #stop_service

Methods included from Mixin::Command

#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Unix

#popen4

Methods included from Mixin::Command::Windows

#popen4

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #node, #resource_collection

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

#data_bag, #data_bag_item, #platform?, #search, #value_for_platform

Constructor Details

#initialize(new_resource, run_context) ⇒ Redhat

Returns a new instance of Redhat



31
32
33
34
35
# File 'lib/chef/provider/service/redhat.rb', line 31

def initialize(new_resource, run_context)
 super
  @init_command = "/sbin/service #{@new_resource.service_name}"
  @new_resource.supports[:status] = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#disable_serviceObject



53
54
55
# File 'lib/chef/provider/service/redhat.rb', line 53

def disable_service()
  shell_out! "/sbin/chkconfig #{@new_resource.service_name} off"
end

#enable_serviceObject



49
50
51
# File 'lib/chef/provider/service/redhat.rb', line 49

def enable_service()
  shell_out! "/sbin/chkconfig #{@new_resource.service_name} on"
end

#load_current_resourceObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/chef/provider/service/redhat.rb', line 37

def load_current_resource
  unless ::File.exists? "/sbin/chkconfig"
    raise Chef::Exceptions::Service, "/sbin/chkconfig does not exist!"
  end
  
  super
  
  chkconfig = shell_out!("/sbin/chkconfig --list #{@current_resource.service_name}", :returns => [0,1])
  @current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON))
  @current_resource        
end