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

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

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods inherited from Init

#reload_service, #restart_service, #start_service, #stop_service

Methods inherited from Simple

#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

handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale

Methods inherited from Chef::Provider

#action_nothing, build_from_file

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string

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(node, new_resource, collection = nil, definitions = nil, cookbook_loader = nil) ⇒ Redhat

Returns a new instance of Redhat.



28
29
30
31
# File 'lib/chef/provider/service/redhat.rb', line 28

def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
 super(node, new_resource, collection, definitions, cookbook_loader)
  @init_command = "/sbin/service #{@new_resource.service_name}"
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



55
56
57
# File 'lib/chef/provider/service/redhat.rb', line 55

def disable_service()
  run_command(:command => "/sbin/chkconfig #{@new_resource.service_name} off")
end

#enable_serviceObject



51
52
53
# File 'lib/chef/provider/service/redhat.rb', line 51

def enable_service()
  run_command(:command => "/sbin/chkconfig #{@new_resource.service_name} on")
end

#load_current_resourceObject



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

def load_current_resource
  super
  
  unless ::File.exists? "/sbin/chkconfig"
    raise Chef::Exceptions::Service, "/sbin/chkconfig does not exist!"
  end

  status = popen4("/sbin/chkconfig --list #{@current_resource.service_name}") do |pid, stdin, stdout, stderr|
    if stdout.gets =~ /\d:on/
      @current_resource.enabled true
    else
      @current_resource.enabled false
    end
  end  

  @current_resource        
end