Class: Chef::Provider::Service::Init

Inherits:
Simple show all
Defined in:
lib/chef/provider/service/init.rb

Direct Known Subclasses

Debian, Freebsd, Gentoo, Redhat

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods inherited from Simple

#load_current_resource

Methods inherited from Chef::Provider::Service

#action_disable, #action_enable, #action_reload, #action_restart, #action_start, #action_stop, #disable_service, #enable_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, #load_current_resource

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #filename_to_qualified_string

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Constructor Details

#initialize(node, new_resource, collection = nil, definitions = nil, cookbook_loader = nil) ⇒ Init

Returns a new instance of Init.



28
29
30
31
# File 'lib/chef/provider/service/init.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 = "/etc/init.d/#{@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

#reload_serviceObject



61
62
63
64
65
66
67
# File 'lib/chef/provider/service/init.rb', line 61

def reload_service
  if @new_resource.reload_command
    super
  elsif @new_resource.supports[:reload]
    run_command(:command => "#{@init_command} reload")
  end
end

#restart_serviceObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/provider/service/init.rb', line 49

def restart_service
  if @new_resource.restart_command
    super
  elsif @new_resource.supports[:restart]
    run_command(:command => "#{@init_command} restart")
  else
    stop_service
    sleep 1
    start_service
  end
end

#start_serviceObject



33
34
35
36
37
38
39
# File 'lib/chef/provider/service/init.rb', line 33

def start_service
  if @new_resource.start_command
    super
  else
    run_command(:command => "#{@init_command} start")
  end
end

#stop_serviceObject



41
42
43
44
45
46
47
# File 'lib/chef/provider/service/init.rb', line 41

def stop_service
  if @new_resource.stop_command
    super
  else
    run_command(:command => "#{@init_command} stop")
  end
end