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

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

Direct Known Subclasses

Arch, Debian, Freebsd, Gentoo, Insserv, Redhat

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Simple

#load_current_resource, #ps_cmd

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

#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale

Methods included from Mixin::Command::Windows

#popen4

Methods included from Mixin::Command::Unix

#popen4

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #cookbook_name, #load_current_resource, #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) ⇒ Init

Returns a new instance of Init.



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

def initialize(new_resource, run_context)
  super
  @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