Class: Chef::Provider::Service::Systemd
Constant Summary
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary collapse
Attributes inherited from Simple
#status_load_success
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Class Method Summary
collapse
Instance Method Summary
collapse
#which
Methods inherited from Simple
#shared_resource_requirements, #whyrun_supported?
#action_disable, #action_enable, #action_reload, #action_restart, #action_start, #action_stop, #initialize, #load_new_resource_state, #shared_resource_requirements, #whyrun_supported?
#chdir_or_tmpdir, #handle_command_failures, #output_of_command, #run_command, #run_command_and_return_stdout_stderr, #run_command_with_systems_locale
#popen4
#popen4
#action_nothing, #cleanup_after_converge, #converge_by, #events, #initialize, #node, node_map, #process_resource_requirements, provides, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Instance Attribute Details
#status_check_success ⇒ Object
Returns the value of attribute status_check_success.
29
30
31
|
# File 'lib/chef/provider/service/systemd.rb', line 29
def status_check_success
@status_check_success
end
|
Class Method Details
.provides?(node, resource) ⇒ Boolean
.supports?(resource, action) ⇒ Boolean
Instance Method Details
#define_resource_requirements ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/chef/provider/service/systemd.rb', line 62
def define_resource_requirements
shared_resource_requirements
requirements.assert(:all_actions) do |a|
a.assertion { status_check_success }
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
120
121
122
|
# File 'lib/chef/provider/service/systemd.rb', line 120
def disable_service
shell_out!("#{systemctl_path} disable #{new_resource.service_name}")
end
|
#enable_service ⇒ Object
116
117
118
|
# File 'lib/chef/provider/service/systemd.rb', line 116
def enable_service
shell_out!("#{systemctl_path} enable #{new_resource.service_name}")
end
|
#is_active? ⇒ Boolean
124
125
126
|
# File 'lib/chef/provider/service/systemd.rb', line 124
def is_active?
shell_out("#{systemctl_path} is-active #{new_resource.service_name} --quiet").exitstatus == 0
end
|
#is_enabled? ⇒ Boolean
128
129
130
|
# File 'lib/chef/provider/service/systemd.rb', line 128
def is_enabled?
shell_out("#{systemctl_path} is-enabled #{new_resource.service_name} --quiet").exitstatus == 0
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
|
# 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
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
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/chef/provider/service/systemd.rb', line 104
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
96
97
98
99
100
101
102
|
# File 'lib/chef/provider/service/systemd.rb', line 96
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
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/chef/provider/service/systemd.rb', line 72
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
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/chef/provider/service/systemd.rb', line 84
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
|