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_encoding, #configure_logging, #configure_proxy_environment_variables, #configure_stdout_logger, debug_stacktrace, exit!, fatal!, #load_config_file, #resolve_log_level, #run, #run_chef_client, #setup_signal_handlers, #using_output_formatter?, #want_additional_logger?

Constructor Details

#initializeSolo

Returns a new instance of Solo.



175
176
177
# File 'lib/chef/application/solo.rb', line 175

def initialize
  super
end

Instance Attribute Details

#chef_client_jsonObject (readonly)

Returns the value of attribute chef_client_json.



173
174
175
# File 'lib/chef/application/solo.rb', line 173

def chef_client_json
  @chef_client_json
end

Instance Method Details

#reconfigureObject



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

def reconfigure
  super

  Chef::Config[:solo] = true

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

  Chef::Application.fatal!(unforked_interval_error_message) if !Chef::Config[:client_fork] && Chef::Config[:interval]

  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)
    tarball_path = File.join(recipes_path, 'recipes.tgz')
    fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path)
    Chef::Mixin::Command.run_command(:command => "tar zxvf #{tarball_path} -C #{recipes_path}")
  end

  # json_attribs shuld be fetched after recipe_url tarball is unpacked.
  # Otherwise it may fail if points to local file from tarball.
  if Chef::Config[:json_attribs]
    config_fetcher = Chef::ConfigFetcher.new(Chef::Config[:json_attribs])
    @chef_client_json = config_fetcher.fetch_json
  end
end

#run_applicationObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/chef/application/solo.rb', line 213

def run_application
  if !Chef::Config[:client_fork] || Chef::Config[:once]
    # Run immediately without interval sleep or splay
    begin
      run_chef_client(Chef::Config[:specific_recipes])
    rescue SystemExit
      raise
    rescue Exception => e
      Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
    end
  else
    interval_run_chef_client
  end
end

#setup_applicationObject



209
210
211
# File 'lib/chef/application/solo.rb', line 209

def setup_application
  Chef::Daemon.change_privilege
end