Class: Chef::Application::Solo

Inherits:
Chef::Application show all
Defined in:
lib/chef/application/solo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Chef::Application

#auto_log_level?, #configure_chef, #configure_logging, #configure_stdout_logger, debug_stacktrace, destroy_server_connectivity, exit!, fatal!, #load_config_file, #resolve_log_level, #run, #run_chef_client, setup_server_connectivity, #using_output_formatter?, #want_additional_logger?

Constructor Details

#initializeSolo

Returns a new instance of Solo.



170
171
172
# File 'lib/chef/application/solo.rb', line 170

def initialize
  super
end

Instance Attribute Details

#chef_client_jsonObject (readonly)

Returns the value of attribute chef_client_json.



168
169
170
# File 'lib/chef/application/solo.rb', line 168

def chef_client_json
  @chef_client_json
end

Instance Method Details

#reconfigureObject



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
# File 'lib/chef/application/solo.rb', line 174

def reconfigure
  super

  Chef::Config[:solo] = true

  if Chef::Config[:daemonize]
    Chef::Config[:interval] ||= 1800
  end

  if Chef::Config[:json_attribs]
    config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs])
    @chef_client_json = config_fetcher.fetch_json
  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, '..'))

    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 zxvf #{path} -C #{recipes_path}")
  end
end

#run_applicationObject



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/chef/application/solo.rb', line 208

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.fatal!("#{e.class}: #{e.message}", 1)
      end
    end
  end
end

#setup_applicationObject



204
205
206
# File 'lib/chef/application/solo.rb', line 204

def setup_application
  Chef::Daemon.change_privilege
end