Class: Chef::Provider::Service::Redhat
- Inherits:
-
Init
- Object
- Chef::Provider
- Chef::Provider::Service
- Simple
- Init
- Chef::Provider::Service::Redhat
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/chef/provider/service/redhat.rb
Constant Summary collapse
- CHKCONFIG_ON =
/\d:on/
- CHKCONFIG_MISSING =
/No such/
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
- #define_resource_requirements ⇒ Object
- #disable_service ⇒ Object
- #enable_service ⇒ Object
-
#initialize(new_resource, run_context) ⇒ Redhat
constructor
A new instance of Redhat.
- #load_current_resource ⇒ Object
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!
Methods inherited from Init
#reload_service, #restart_service, #start_service, #stop_service
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, #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
Methods included from Mixin::Command::Unix
Methods inherited from Chef::Provider
#action_nothing, build_from_file, #cleanup_after_converge, #converge, #cookbook_name, #events, #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
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #platform_family?, #search, #value_for_platform, #value_for_platform_family
Constructor Details
#initialize(new_resource, run_context) ⇒ Redhat
Returns a new instance of Redhat.
32 33 34 35 36 37 |
# File 'lib/chef/provider/service/redhat.rb', line 32 def initialize(new_resource, run_context) super @init_command = "/sbin/service #{@new_resource.service_name}" @new_resource.supports[:status] = true @service_missing = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#define_resource_requirements ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/chef/provider/service/redhat.rb', line 39 def define_resource_requirements shared_resource_requirements requirements.assert(:all_actions) do |a| chkconfig_file = "/sbin/chkconfig" a.assertion { ::File.exists? chkconfig_file } a. Chef::Exceptions::Service, "#{chkconfig_file} does not exist!" end requirements.assert(:start, :enable, :reload, :restart) do |a| a.assertion { !@service_missing } a. Chef::Exceptions::Service, "#{@new_resource}: unable to locate the init.d script!" a.whyrun "Assuming service would be disabled. The init script is not presently installed." end end |
#disable_service ⇒ Object
71 72 73 |
# File 'lib/chef/provider/service/redhat.rb', line 71 def disable_service() shell_out! "/sbin/chkconfig #{@new_resource.service_name} off" end |
#enable_service ⇒ Object
67 68 69 |
# File 'lib/chef/provider/service/redhat.rb', line 67 def enable_service() shell_out! "/sbin/chkconfig #{@new_resource.service_name} on" end |
#load_current_resource ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/chef/provider/service/redhat.rb', line 55 def load_current_resource super if ::File.exists?("/sbin/chkconfig") chkconfig = shell_out!("/sbin/chkconfig --list #{@current_resource.service_name}", :returns => [0,1]) @current_resource.enabled(!!(chkconfig.stdout =~ CHKCONFIG_ON)) @service_missing = !!(chkconfig.stderr =~ CHKCONFIG_MISSING) end @current_resource end |