Class: Chef::Provider::Launchd
Constant Summary
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary
#action, #cookbook_name, #current_resource, #new_resource, #recipe_name, #run_context
Instance Method Summary
collapse
#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, 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
#const_missing, #deprecated_constants, #register_deprecated_lwrp_class
#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
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
#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
59
60
61
|
# File 'lib/chef/provider/launchd.rb', line 59
def action_create
manage_plist(:create)
end
|
#action_create_if_missing ⇒ Object
63
64
65
|
# File 'lib/chef/provider/launchd.rb', line 63
def action_create_if_missing
manage_plist(:create_if_missing)
end
|
#action_delete ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/chef/provider/launchd.rb', line 67
def action_delete
if ::File.exists?(@path)
manage_service(:disable)
end
manage_plist(:delete)
end
|
#action_disable ⇒ Object
84
85
86
|
# File 'lib/chef/provider/launchd.rb', line 84
def action_disable
manage_service(:disable)
end
|
#action_enable ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/chef/provider/launchd.rb', line 76
def action_enable
if manage_plist(:create)
manage_service(:restart)
else
manage_service(:enable)
end
end
|
#content ⇒ Object
152
153
154
155
|
# File 'lib/chef/provider/launchd.rb', line 152
def content
plist_hash = new_resource.hash || gen_hash
Plist::Emit.dump(plist_hash) unless plist_hash.nil?
end
|
#content? ⇒ Boolean
148
149
150
|
# File 'lib/chef/provider/launchd.rb', line 148
def content?
!!content
end
|
#cookbook_file_resource ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/chef/provider/launchd.rb', line 125
def cookbook_file_resource
res = Chef::Resource::CookbookFile.new(@path, run_context)
res.cookbook_name = cookbook if cookbook
res.name(@path) if @path
res.backup(backup) if backup
res.group(group) if group
res.mode(mode) if mode
res.owner(owner) if owner
res.source(source) if source
res
end
|
#define_resource_requirements ⇒ Object
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/chef/provider/launchd.rb', line 137
def define_resource_requirements
requirements.assert(
:create, :create_if_missing, :delete, :enable, :disable
) do |a|
type = new_resource.type
a.assertion { %w{daemon agent}.include?(type.to_s) }
error_msg = "type must be daemon or agent."
a.failure_message Chef::Exceptions::ValidationFailed, error_msg
end
end
|
#file_resource ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/chef/provider/launchd.rb', line 114
def file_resource
res = Chef::Resource::File.new(@path, run_context)
res.name(@path) if @path
res.backup(backup) if backup
res.content(content) if content
res.group(group) if group
res.mode(mode) if mode
res.owner(owner) if owner
res
end
|
#gen_hash ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/chef/provider/launchd.rb', line 157
def gen_hash
return nil unless new_resource.program || new_resource.program_arguments
{
"label" => "Label",
"program" => "Program",
"program_arguments" => "ProgramArguments",
"abandon_process_group" => "AbandonProcessGroup",
"debug" => "Debug",
"disabled" => "Disabled",
"enable_globbing" => "EnableGlobbing",
"enable_transactions" => "EnableTransactions",
"environment_variables" => "EnvironmentVariables",
"exit_timeout" => "ExitTimeout",
"ld_group" => "GroupName",
"hard_resource_limits" => "HardreSourceLimits",
"inetd_compatibility" => "inetdCompatibility",
"init_groups" => "InitGroups",
"keep_alive" => "KeepAlive",
"launch_only_once" => "LaunchOnlyOnce",
"limit_load_from_hosts" => "LimitLoadFromHosts",
"limit_load_to_hosts" => "LimitLoadToHosts",
"limit_load_to_session_type" => "LimitLoadToSessionType",
"low_priority_io" => "LowPriorityIO",
"mach_services" => "MachServices",
"nice" => "Nice",
"on_demand" => "OnDemand",
"process_type" => "ProcessType",
"queue_directories" => "QueueDirectories",
"root_directory" => "RootDirectory",
"run_at_load" => "RunAtLoad",
"sockets" => "Sockets",
"soft_resource_limits" => "SoftResourceLimits",
"standard_error_path" => "StandardErrorPath",
"standard_in_path" => "StandardInPath",
"standard_out_path" => "StandardOutPath",
"start_calendar_interval" => "StartCalendarInterval",
"start_interval" => "StartInterval",
"start_on_mount" => "StartOnMount",
"throttle_interval" => "ThrottleInterval",
"time_out" => "TimeOut",
"umask" => "Umask",
"username" => "UserName",
"wait_for_debugger" => "WaitForDebugger",
"watch_paths" => "WatchPaths",
"working_directory" => "WorkingDirectory",
}.each_with_object({}) do |(key, val), memo|
memo[val] = new_resource.send(key) if new_resource.send(key)
end
end
|
#gen_path_from_type ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/chef/provider/launchd.rb', line 51
def gen_path_from_type
types = {
"daemon" => "/Library/LaunchDaemons/#{label}.plist",
"agent" => "/Library/LaunchAgents/#{label}.plist",
}
types[type]
end
|
#load_current_resource ⇒ Object
46
47
48
49
|
# File 'lib/chef/provider/launchd.rb', line 46
def load_current_resource
current_resource = Chef::Resource::Launchd.new(new_resource.name)
@path = path ? path : gen_path_from_type
end
|
#manage_plist(action) ⇒ Object
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/chef/provider/launchd.rb', line 88
def manage_plist(action)
if source
res = cookbook_file_resource
else
res = file_resource
end
res.run_action(action)
new_resource.updated_by_last_action(true) if res.updated?
res.updated
end
|
#manage_service(action) ⇒ Object
99
100
101
102
103
|
# File 'lib/chef/provider/launchd.rb', line 99
def manage_service(action)
res = service_resource
res.run_action(action)
new_resource.updated_by_last_action(true) if res.updated?
end
|
#service_resource ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/chef/provider/launchd.rb', line 105
def service_resource
res = Chef::Resource::MacosxService.new(label, run_context)
res.name(label) if label
res.service_name(label) if label
res.plist(@path) if @path
res.session_type(session_type) if session_type
res
end
|