Class: Chef::Provider::SystemdUnit
Instance Attribute Summary
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Instance Method Summary
collapse
#a_to_s, #clean_array, #shell_out, #shell_out!, #shell_out_compact, #shell_out_compact!, #shell_out_compact_timeout, #shell_out_compact_timeout!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
#enforce_path_sanity, #sanitized_path
#where, #which
action, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #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, supports?, use_inline_resources, #whyrun_mode?, #whyrun_supported?
#provided_as, #provides, #provides?
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
#descendants, #include, #included
#notifying_block, #subcontext_block
#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #with_run_context
#powershell_out, #powershell_out!
#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
#docker?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family
Constructor Details
This class inherits a constructor from Chef::Provider
Instance Method Details
#action_create ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/chef/provider/systemd_unit.rb', line 58
def action_create
if current_resource.content != new_resource.to_ini
converge_by("creating unit: #{new_resource.name}") do
manage_unit_file(:create)
daemon_reload if new_resource.triggers_reload
end
end
end
|
#action_delete ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/chef/provider/systemd_unit.rb', line 67
def action_delete
if ::File.exist?(unit_path)
converge_by("deleting unit: #{new_resource.name}") do
manage_unit_file(:delete)
daemon_reload if new_resource.triggers_reload
end
end
end
|
#action_disable ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/chef/provider/systemd_unit.rb', line 88
def action_disable
if current_resource.static
Chef::Log.debug("#{new_resource.name} is a static unit, disabling is a NOP.")
end
if current_resource.enabled && !current_resource.static
converge_by("disabling unit: #{new_resource.name}") do
systemctl_execute!(:disable, new_resource.name)
end
end
end
|
#action_enable ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/chef/provider/systemd_unit.rb', line 76
def action_enable
if current_resource.static
Chef::Log.debug("#{new_resource.name} is a static unit, enabling is a NOP.")
end
unless current_resource.enabled || current_resource.static
converge_by("enabling unit: #{new_resource.name}") do
systemctl_execute!(:enable, new_resource.name)
end
end
end
|
#action_mask ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/chef/provider/systemd_unit.rb', line 100
def action_mask
unless current_resource.masked
converge_by("masking unit: #{new_resource.name}") do
systemctl_execute!(:mask, new_resource.name)
end
end
end
|
#action_reload ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/chef/provider/systemd_unit.rb', line 138
def action_reload
if current_resource.active
converge_by("reloading unit: #{new_resource.name}") do
systemctl_execute!(:reload, new_resource.name)
end
else
Chef::Log.debug("#{new_resource.name} is not active, skipping reload.")
end
end
|
#action_reload_or_restart ⇒ Object
154
155
156
157
158
|
# File 'lib/chef/provider/systemd_unit.rb', line 154
def action_reload_or_restart
converge_by("reload-or-restarting unit: #{new_resource.name}") do
systemctl_execute!("reload-or-restart", new_resource.name)
end
end
|
#action_reload_or_try_restart ⇒ Object
160
161
162
163
164
|
# File 'lib/chef/provider/systemd_unit.rb', line 160
def action_reload_or_try_restart
converge_by("reload-or-try-restarting unit: #{new_resource.name}") do
systemctl_execute!("reload-or-try-restart", new_resource.name)
end
end
|
#action_restart ⇒ Object
132
133
134
135
136
|
# File 'lib/chef/provider/systemd_unit.rb', line 132
def action_restart
converge_by("restarting unit: #{new_resource.name}") do
systemctl_execute!(:restart, new_resource.name)
end
end
|
#action_start ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/chef/provider/systemd_unit.rb', line 116
def action_start
unless current_resource.active
converge_by("starting unit: #{new_resource.name}") do
systemctl_execute!(:start, new_resource.name)
end
end
end
|
#action_stop ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/chef/provider/systemd_unit.rb', line 124
def action_stop
if current_resource.active
converge_by("stopping unit: #{new_resource.name}") do
systemctl_execute!(:stop, new_resource.name)
end
end
end
|
#action_try_restart ⇒ Object
148
149
150
151
152
|
# File 'lib/chef/provider/systemd_unit.rb', line 148
def action_try_restart
converge_by("try-restarting unit: #{new_resource.name}") do
systemctl_execute!("try-restart", new_resource.name)
end
end
|
#action_unmask ⇒ Object
108
109
110
111
112
113
114
|
# File 'lib/chef/provider/systemd_unit.rb', line 108
def action_unmask
if current_resource.masked
converge_by("unmasking unit: #{new_resource.name}") do
systemctl_execute!(:unmask, new_resource.name)
end
end
end
|
#active? ⇒ Boolean
166
167
168
|
# File 'lib/chef/provider/systemd_unit.rb', line 166
def active?
systemctl_execute("is-active", new_resource.name).exitstatus == 0
end
|
#define_resource_requirements ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/chef/provider/systemd_unit.rb', line 49
def define_resource_requirements
super
requirements.assert(:create) do |a|
a.assertion { IniParse.parse(new_resource.to_ini) }
a.failure_message "Unit content is not valid INI text"
end
end
|
#enabled? ⇒ Boolean
170
171
172
|
# File 'lib/chef/provider/systemd_unit.rb', line 170
def enabled?
systemctl_execute("is-enabled", new_resource.name).exitstatus == 0
end
|
#load_current_resource ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/chef/provider/systemd_unit.rb', line 35
def load_current_resource
@current_resource = Chef::Resource::SystemdUnit.new(new_resource.name)
current_resource.content(::File.read(unit_path)) if ::File.exist?(unit_path)
current_resource.user(new_resource.user)
current_resource.enabled(enabled?)
current_resource.active(active?)
current_resource.masked(masked?)
current_resource.static(static?)
current_resource.triggers_reload(new_resource.triggers_reload)
current_resource
end
|
#masked? ⇒ Boolean
174
175
176
|
# File 'lib/chef/provider/systemd_unit.rb', line 174
def masked?
systemctl_execute(:status, new_resource.name).stdout.include?("masked")
end
|
#static? ⇒ Boolean
178
179
180
|
# File 'lib/chef/provider/systemd_unit.rb', line 178
def static?
systemctl_execute("is-enabled", new_resource.name).stdout.include?("static")
end
|