Class: Chef::Provider::Service::Systemd
- Inherits:
-
Simple
- Object
- Chef::Provider
- Chef::Provider::Service
- Simple
- Chef::Provider::Service::Systemd
- Includes:
- Mixin::Which
- Defined in:
- lib/chef/provider/service/systemd.rb
Constant Summary
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary collapse
-
#status_check_success ⇒ Object
Returns the value of attribute status_check_success.
Attributes inherited from Simple
Attributes inherited from Chef::Provider
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Class Method Summary collapse
Instance Method Summary collapse
- #define_resource_requirements ⇒ Object
- #disable_service ⇒ Object
- #enable_service ⇒ Object
- #is_active? ⇒ Boolean
- #is_enabled? ⇒ Boolean
- #load_current_resource ⇒ Object
- #reload_service ⇒ Object
- #restart_service ⇒ Object
- #start_service ⇒ Object
- #stop_service ⇒ Object
Methods included from Mixin::Which
Methods inherited from Simple
#shared_resource_requirements, #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, #shared_resource_requirements, #supports, #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, #check_resource_semantics!, #cleanup_after_converge, #converge_by, #converge_if_changed, #events, include_resource_dsl, include_resource_dsl_module, #initialize, #node, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, use_inline_resources, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::Provides
#provided_as, #provides, #provides?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Methods included from DeprecatedLWRPClass
#const_missing, #register_deprecated_lwrp_class
Methods included from Mixin::PowershellOut
#powershell_out, #powershell_out!
Methods included from Mixin::WindowsArchitectureHelper
#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Constructor Details
This class inherits a constructor from Chef::Provider::Service
Instance Attribute Details
#status_check_success ⇒ Object
Returns the value of attribute status_check_success.
31 32 33 |
# File 'lib/chef/provider/service/systemd.rb', line 31 def status_check_success @status_check_success end |
Class Method Details
.supports?(resource, action) ⇒ Boolean
33 34 35 |
# File 'lib/chef/provider/service/systemd.rb', line 33 def self.supports?(resource, action) Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:systemd) end |
Instance Method Details
#define_resource_requirements ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/chef/provider/service/systemd.rb', line 60 def define_resource_requirements shared_resource_requirements requirements.assert(:all_actions) do |a| a.assertion { status_check_success } # We won't stop in any case, but in whyrun warn and tell what we're doing. a.whyrun ["Failed to determine status of #{new_resource}, using command #{new_resource.status_command}.", "Assuming service would have been installed and is disabled"] end end |
#disable_service ⇒ Object
118 119 120 |
# File 'lib/chef/provider/service/systemd.rb', line 118 def disable_service shell_out!("#{systemctl_path} disable #{new_resource.service_name}") end |
#enable_service ⇒ Object
114 115 116 |
# File 'lib/chef/provider/service/systemd.rb', line 114 def enable_service shell_out!("#{systemctl_path} enable #{new_resource.service_name}") end |
#is_active? ⇒ Boolean
122 123 124 |
# File 'lib/chef/provider/service/systemd.rb', line 122 def is_active? shell_out("#{systemctl_path} is-active #{new_resource.service_name} --quiet").exitstatus == 0 end |
#is_enabled? ⇒ Boolean
126 127 128 |
# File 'lib/chef/provider/service/systemd.rb', line 126 def is_enabled? shell_out("#{systemctl_path} is-enabled #{new_resource.service_name} --quiet").exitstatus == 0 end |
#load_current_resource ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/provider/service/systemd.rb', line 37 def load_current_resource @current_resource = Chef::Resource::Service.new(new_resource.name) current_resource.service_name(new_resource.service_name) @status_check_success = true if new_resource.status_command Chef::Log.debug("#{new_resource} you have specified a status command, running..") unless shell_out(new_resource.status_command).error? current_resource.running(true) else @status_check_success = false current_resource.running(false) current_resource.enabled(false) end else current_resource.running(is_active?) end current_resource.enabled(is_enabled?) current_resource end |
#reload_service ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/chef/provider/service/systemd.rb', line 102 def reload_service if new_resource.reload_command super else if current_resource.running shell_out_with_systems_locale!("#{systemctl_path} reload #{new_resource.service_name}") else start_service end end end |
#restart_service ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/chef/provider/service/systemd.rb', line 94 def restart_service if new_resource.restart_command super else shell_out_with_systems_locale!("#{systemctl_path} restart #{new_resource.service_name}") end end |
#start_service ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/chef/provider/service/systemd.rb', line 70 def start_service if current_resource.running Chef::Log.debug("#{new_resource} already running, not starting") else if new_resource.start_command super else shell_out_with_systems_locale!("#{systemctl_path} start #{new_resource.service_name}") end end end |
#stop_service ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/chef/provider/service/systemd.rb', line 82 def stop_service unless current_resource.running Chef::Log.debug("#{new_resource} not running, not stopping") else if new_resource.stop_command super else shell_out_with_systems_locale!("#{systemctl_path} stop #{new_resource.service_name}") end end end |