Class: Chef::Provider::Service::Openbsd
- Inherits:
-
Init
- Object
- Chef::Provider
- Chef::Provider::Service
- Simple
- Init
- Chef::Provider::Service::Openbsd
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/chef/provider/service/openbsd.rb
Constant Summary collapse
- RC_CONF_PATH =
'/etc/rc.conf'- RC_CONF_LOCAL_PATH =
'/etc/rc.conf.local'
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary collapse
-
#enabled_state_found ⇒ Object
readonly
Returns the value of attribute enabled_state_found.
-
#init_command ⇒ Object
readonly
Returns the value of attribute init_command.
-
#rc_conf ⇒ Object
readonly
Returns the value of attribute rc_conf.
-
#rc_conf_local ⇒ Object
readonly
Returns the value of attribute rc_conf_local.
Attributes inherited from Simple
Attributes inherited from Chef::Provider
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Instance Method Summary collapse
- #define_resource_requirements ⇒ Object
- #disable_service ⇒ Object
- #enable_service ⇒ Object
-
#initialize(new_resource, run_context) ⇒ Openbsd
constructor
A new instance of Openbsd.
- #load_current_resource ⇒ Object
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Methods inherited from Init
#reload_service, #restart_service, #start_service, #stop_service, supports?
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_and_return_stdout_stderr, #run_command_with_systems_locale
Methods included from Mixin::Command::Windows
Methods included from Mixin::Command::Unix
Methods inherited from Chef::Provider
#action_nothing, #cleanup_after_converge, #converge_by, #events, #node, node_map, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Constructor Details
#initialize(new_resource, run_context) ⇒ Openbsd
Returns a new instance of Openbsd.
38 39 40 41 42 43 44 45 |
# File 'lib/chef/provider/service/openbsd.rb', line 38 def initialize(new_resource, run_context) super @rc_conf = ::File.read(RC_CONF_PATH) rescue '' @rc_conf_local = ::File.read(RC_CONF_LOCAL_PATH) rescue '' @init_command = ::File.exist?(rcd_script_path) ? rcd_script_path : nil new_resource.supports[:status] = true new_resource.status_command("#{default_init_command} check") end |
Instance Attribute Details
#enabled_state_found ⇒ Object (readonly)
Returns the value of attribute enabled_state_found.
33 34 35 |
# File 'lib/chef/provider/service/openbsd.rb', line 33 def enabled_state_found @enabled_state_found end |
#init_command ⇒ Object (readonly)
Returns the value of attribute init_command.
33 34 35 |
# File 'lib/chef/provider/service/openbsd.rb', line 33 def init_command @init_command end |
#rc_conf ⇒ Object (readonly)
Returns the value of attribute rc_conf.
33 34 35 |
# File 'lib/chef/provider/service/openbsd.rb', line 33 def rc_conf @rc_conf end |
#rc_conf_local ⇒ Object (readonly)
Returns the value of attribute rc_conf_local.
33 34 35 |
# File 'lib/chef/provider/service/openbsd.rb', line 33 def rc_conf_local @rc_conf_local end |
Instance Method Details
#define_resource_requirements ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef/provider/service/openbsd.rb', line 58 def define_resource_requirements shared_resource_requirements requirements.assert(:start, :enable, :reload, :restart) do |a| a.assertion { init_command } a. Chef::Exceptions::Service, "#{new_resource}: unable to locate the rc.d script" end requirements.assert(:all_actions) do |a| a.assertion { enabled_state_found } # for consistency with original behavior, this will not fail in non-whyrun mode; # rather it will silently set enabled state=>false a.whyrun "Unable to determine enabled/disabled state, assuming this will be correct for an actual run. Assuming disabled." end requirements.assert(:start, :enable, :reload, :restart) do |a| a.assertion { init_command && builtin_service_enable_variable_name != nil } a. Chef::Exceptions::Service, "Could not find the service name in #{init_command} and rcvar" # No recovery in whyrun mode - the init file is present but not correct. end end |
#disable_service ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/chef/provider/service/openbsd.rb', line 104 def disable_service if is_enabled? if is_builtin? if is_enabled_by_default? # add line to disable update_rcl rc_conf_local + "\n" + "#{builtin_service_enable_variable_name}=\"NO\"\n" else # remove line to disable update_rcl rc_conf_local.sub(/^#{Regexp.escape(builtin_service_enable_variable_name)}=.*/, '') end else # remove from pkg_scripts old_list = rc_conf_local.match(/^pkg_scripts="(.*)"/) old_list = old_list ? old_list[1].split(' ') : [] new_list = old_list - [new_resource.service_name] update_rcl rc_conf_local.sub(/^pkg_scripts="(.*)"/, pkg_scripts="#{new_list.join(' ')}") end end end |
#enable_service ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/chef/provider/service/openbsd.rb', line 80 def enable_service if !is_enabled? if is_builtin? if is_enabled_by_default? update_rcl rc_conf_local.sub(/^#{Regexp.escape(builtin_service_enable_variable_name)}=.*/, '') else # add line with blank string, which means enable update_rcl rc_conf_local + "\n" + "#{builtin_service_enable_variable_name}=\"\"\n" end else # add to pkg_scripts, most recent addition goes last old_services_list = rc_conf_local.match(/^pkg_scripts="(.*)"/) old_services_list = old_services_list ? old_services_list[1].split(' ') : [] new_services_list = old_services_list + [new_resource.service_name] if rc_conf_local.match(/^pkg_scripts="(.*)"/) new_rcl = rc_conf_local.sub(/^pkg_scripts="(.*)"/, "pkg_scripts=\"#{new_services_list.join(' ')}\"") else new_rcl = rc_conf_local + "\n" + "pkg_scripts=\"#{new_services_list.join(' ')}\"\n" end update_rcl new_rcl end end end |
#load_current_resource ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chef/provider/service/openbsd.rb', line 47 def load_current_resource @current_resource = Chef::Resource::Service.new(new_resource.name) current_resource.service_name(new_resource.service_name) Chef::Log.debug("#{current_resource} found at #{init_command}") determine_current_status! determine_enabled_status! current_resource end |