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
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, #current_resource, #logger, #new_resource, #recipe_name, #run_context
Class Method Summary collapse
Instance Method Summary collapse
- #define_resource_requirements ⇒ Object
- #disable_service ⇒ Object
- #enable_service ⇒ Object
- #get_systemctl_options_args ⇒ Object
- #is_active? ⇒ Boolean
- #is_enabled? ⇒ Boolean
- #is_indirect? ⇒ Boolean
- #is_masked? ⇒ Boolean
- #load_current_resource ⇒ Object
- #mask_service ⇒ Object
- #reload_service ⇒ Object
- #restart_service ⇒ Object
- #start_service ⇒ Object
- #stop_service ⇒ Object
- #unmask_service ⇒ Object
-
#user_services_requirements ⇒ Object
systemd supports user services just fine.
Methods inherited from Simple
Methods inherited from Chef::Provider::Service
#action_disable, #action_enable, #action_mask, #action_reload, #action_restart, #action_start, #action_stop, #action_unmask, #initialize, #load_new_resource_state, #shared_resource_requirements, #supports
Methods inherited from Chef::Provider
action, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #cookbook_name, #description, #events, include_resource_dsl?, include_resource_dsl_module, #initialize, #introduced, #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 Mixin::LazyModuleInclude
#descendants, #include, #included
Methods included from Mixin::ShellOut
apply_default_env, maybe_add_timeout, #shell_out, #shell_out!
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::PowershellExec
Methods included from DSL::Powershell
Methods included from DSL::RegistryHelper
#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?
Methods included from DSL::DataQuery
#data_bag, #data_bag_item, #search, #tagged?
Methods included from EncryptedDataBagItem::CheckEncrypted
Methods included from DSL::PlatformIntrospection
#older_than_win_2012_or_8?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family
Methods included from Mixin::NotifyingBlock
#notifying_block, #subcontext_block
Methods included from DSL::DeclareResource
#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #resources, #with_run_context
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.
33 34 35 |
# File 'lib/chef/provider/service/systemd.rb', line 33 def status_check_success @status_check_success end |
Class Method Details
.supports?(resource, action) ⇒ Boolean
35 36 37 |
# File 'lib/chef/provider/service/systemd.rb', line 35 def self.supports?(resource, action) service_script_exist?(:systemd, resource.service_name) end |
Instance Method Details
#define_resource_requirements ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/chef/provider/service/systemd.rb', line 69 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
156 157 158 159 160 161 162 163 |
# File 'lib/chef/provider/service/systemd.rb', line 156 def disable_service if current_resource.masked || current_resource.indirect logger.trace("#{new_resource} cannot be disabled: it is masked or indirect") return end , args = shell_out!("#{systemctl_path} #{args} disable #{Shellwords.escape(new_resource.service_name)}", **) end |
#enable_service ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/chef/provider/service/systemd.rb', line 147 def enable_service if current_resource.masked || current_resource.indirect logger.trace("#{new_resource} cannot be enabled: it is masked or indirect") return end , args = shell_out!("#{systemctl_path} #{args} enable #{Shellwords.escape(new_resource.service_name)}", **) end |
#get_systemctl_options_args ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/chef/provider/service/systemd.rb', line 79 def if new_resource.user raise NotImplementedError, "#{new_resource} does not support the user property on a target_mode host (yet)" if Chef::Config.target_mode? uid = Etc.getpwnam(new_resource.user).uid = { environment: { "DBUS_SESSION_BUS_ADDRESS" => "unix:path=/run/user/#{uid}/bus", }, user: new_resource.user, } args = "--user" else = {} args = "--system" end [, args] end |
#is_active? ⇒ Boolean
175 176 177 178 |
# File 'lib/chef/provider/service/systemd.rb', line 175 def is_active? , args = shell_out("#{systemctl_path} #{args} is-active #{Shellwords.escape(new_resource.service_name)} --quiet", **).exitstatus == 0 end |
#is_enabled? ⇒ Boolean
180 181 182 183 |
# File 'lib/chef/provider/service/systemd.rb', line 180 def is_enabled? , args = shell_out("#{systemctl_path} #{args} is-enabled #{Shellwords.escape(new_resource.service_name)} --quiet", **).exitstatus == 0 end |
#is_indirect? ⇒ Boolean
185 186 187 188 189 |
# File 'lib/chef/provider/service/systemd.rb', line 185 def is_indirect? , args = s = shell_out("#{systemctl_path} #{args} is-enabled #{Shellwords.escape(new_resource.service_name)}", **) s.stdout.include?("indirect") end |
#is_masked? ⇒ Boolean
191 192 193 194 195 |
# File 'lib/chef/provider/service/systemd.rb', line 191 def is_masked? , args = s = shell_out("#{systemctl_path} #{args} is-enabled #{Shellwords.escape(new_resource.service_name)}", **) s.exitstatus != 0 && s.stdout.include?("masked") end |
#load_current_resource ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/chef/provider/service/systemd.rb', line 39 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 logger.trace("#{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) current_resource.masked(false) current_resource.indirect(false) end else current_resource.running(is_active?) end current_resource.enabled(is_enabled?) current_resource.masked(is_masked?) current_resource.indirect(is_indirect?) current_resource end |
#mask_service ⇒ Object
165 166 167 168 |
# File 'lib/chef/provider/service/systemd.rb', line 165 def mask_service , args = shell_out!("#{systemctl_path} #{args} mask #{Shellwords.escape(new_resource.service_name)}", **) end |
#reload_service ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/chef/provider/service/systemd.rb', line 134 def reload_service if new_resource.reload_command super else if current_resource.running , args = shell_out!("#{systemctl_path} #{args} reload #{Shellwords.escape(new_resource.service_name)}", default_env: false, **) else start_service end end end |
#restart_service ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/chef/provider/service/systemd.rb', line 125 def restart_service if new_resource.restart_command super else , args = shell_out!("#{systemctl_path} #{args} restart #{Shellwords.escape(new_resource.service_name)}", default_env: false, **) end end |
#start_service ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/chef/provider/service/systemd.rb', line 99 def start_service if current_resource.running logger.trace("#{new_resource} already running, not starting") else if new_resource.start_command super else , args = shell_out!("#{systemctl_path} #{args} start #{Shellwords.escape(new_resource.service_name)}", default_env: false, **) end end end |
#stop_service ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/chef/provider/service/systemd.rb', line 112 def stop_service unless current_resource.running logger.trace("#{new_resource} not running, not stopping") else if new_resource.stop_command super else , args = shell_out!("#{systemctl_path} #{args} stop #{Shellwords.escape(new_resource.service_name)}", default_env: false, **) end end end |
#unmask_service ⇒ Object
170 171 172 173 |
# File 'lib/chef/provider/service/systemd.rb', line 170 def unmask_service , args = shell_out!("#{systemctl_path} #{args} unmask #{Shellwords.escape(new_resource.service_name)}", **) end |
#user_services_requirements ⇒ Object
systemd supports user services just fine
67 |
# File 'lib/chef/provider/service/systemd.rb', line 67 def user_services_requirements; end |