Class: Chef::Application::Solo
Instance Attribute Summary collapse
Instance Method Summary
collapse
#auto_log_level?, #configure_chef, #configure_logging, #configure_stdout_logger, debug_stacktrace, exit!, fatal!, #resolve_log_level, #run, #run_chef_client, #using_output_formatter?, #want_additional_logger?
Constructor Details
#initialize ⇒ Solo
165
166
167
|
# File 'lib/chef/application/solo.rb', line 165
def initialize
super
end
|
Instance Attribute Details
#chef_solo_json ⇒ Object
Returns the value of attribute chef_solo_json.
163
164
165
|
# File 'lib/chef/application/solo.rb', line 163
def chef_solo_json
@chef_solo_json
end
|
Instance Method Details
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/chef/application/solo.rb', line 169
def reconfigure
super
Chef::Config[:solo] = true
if Chef::Config[:daemonize]
Chef::Config[:interval] ||= 1800
end
if Chef::Config[:json_attribs]
begin
json_io = case Chef::Config[:json_attribs]
when /^(http|https):\/\//
@rest = Chef::REST.new(Chef::Config[:json_attribs], nil, nil)
@rest.get_rest(Chef::Config[:json_attribs], true).open
else
open(Chef::Config[:json_attribs])
end
rescue SocketError => error
Chef::Application.fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2)
rescue Errno::ENOENT => error
Chef::Application.fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2)
rescue Errno::EACCES => error
Chef::Application.fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2)
rescue Exception => error
Chef::Application.fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.message}", 2)
end
begin
@chef_client_json = Chef::JSONCompat.from_json(json_io.read)
json_io.close unless json_io.closed?
rescue JSON::ParserError => error
Chef::Application.fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2)
end
end
if Chef::Config[:recipe_url]
cookbooks_path = Array(Chef::Config[:cookbook_path]).detect{|e| e =~ /\/cookbooks\/*$/ }
recipes_path = File.expand_path(File.join(cookbooks_path, '..'))
target_file = File.join(recipes_path, 'recipes.tgz')
Chef::Log.debug "Creating path #{recipes_path} to extract recipes into"
FileUtils.mkdir_p recipes_path
path = File.join(recipes_path, 'recipes.tgz')
File.open(path, 'wb') do |f|
open(Chef::Config[:recipe_url]) do |r|
f.write(r.read)
end
end
Chef::Mixin::Command.run_command(:command => "tar zxvfC #{path} #{recipes_path}")
end
end
|
#run_application ⇒ Object
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/chef/application/solo.rb', line 226
def run_application
if Chef::Config[:daemonize]
Chef::Daemon.daemonize("chef-client")
end
loop do
begin
if Chef::Config[:splay]
splay = rand Chef::Config[:splay]
Chef::Log.debug("Splay sleep #{splay} seconds")
sleep splay
end
run_chef_client
if Chef::Config[:interval]
Chef::Log.debug("Sleeping for #{Chef::Config[:interval]} seconds")
sleep Chef::Config[:interval]
else
Chef::Application.exit! "Exiting", 0
end
rescue SystemExit => e
raise
rescue Exception => e
if Chef::Config[:interval]
Chef::Log.error("#{e.class}: #{e}")
Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}")
Chef::Log.fatal("Sleeping for #{Chef::Config[:interval]} seconds before trying again")
sleep Chef::Config[:interval]
retry
else
Chef::Application.debug_stacktrace(e)
Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
end
end
end
end
|
#setup_application ⇒ Object
222
223
224
|
# File 'lib/chef/application/solo.rb', line 222
def setup_application
Chef::Daemon.change_privilege
end
|