Class: Chef::Provider::Service::Gentoo

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

Constant Summary

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Attribute Summary

Attributes inherited from Chef::Provider

#action, #current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods inherited from Init

#initialize, #reload_service, #restart_service, #start_service, #stop_service

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!

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, #initialize, #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_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, #cleanup_after_converge, #converge, #cookbook_name, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #whyrun_mode?, #whyrun_supported?

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Methods included from Mixin::EnforceOwnershipAndPermissions

#access_controls, #enforce_ownership_and_permissions

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

Methods included from Mixin::Language

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

Constructor Details

This class inherits a constructor from Chef::Provider::Service::Init

Dynamic Method Handling

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

Instance Method Details

#define_resource_requirementsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/chef/provider/service/gentoo.rb', line 45

def define_resource_requirements
  requirements.assert(:all_actions) do |a|
    a.assertion { ::File.exists?("/sbin/rc-update") } 
    a.failure_message Chef::Exceptions::Service, "/sbin/rc-update does not exist"
    # no whyrun recovery -t his is a core component whose presence is
    # unlikely to be affected by what we do in the course of a chef run
  end

  requirements.assert(:all_actions) do |a|
    a.assertion { @found_script }
    # No failure, just informational output from whyrun 
    a.whyrun "Could not find service #{@new_resource.service_name} under any runlevel"
  end
end

#disable_serviceObject



64
65
66
# File 'lib/chef/provider/service/gentoo.rb', line 64

def disable_service()
  run_command(:command => "/sbin/rc-update del #{@new_resource.service_name} default")
end

#enable_serviceObject



60
61
62
# File 'lib/chef/provider/service/gentoo.rb', line 60

def enable_service()
  run_command(:command => "/sbin/rc-update add #{@new_resource.service_name} default")
end

#load_current_resourceObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chef/provider/service/gentoo.rb', line 24

def load_current_resource

  @new_resource.supports[:status] = true
  @new_resource.supports[:restart] = true
  @found_script = false
  super

  @current_resource.enabled(
    Dir.glob("/etc/runlevels/**/#{@current_resource.service_name}").any? do |file|
      @found_script = true
      exists = ::File.exists? file
      readable = ::File.readable? file
      Chef::Log.debug "#{@new_resource} exists: #{exists}, readable: #{readable}"
      exists and readable
    end
  )
  Chef::Log.debug "#{@new_resource} enabled: #{@current_resource.enabled}"

  @current_resource
end