# class Chef::Application::Solo

### Attributes

chef_client_json[R]

### Public Class Methods

new() click to toggle source
Calls superclass method Chef::Application.new

    # File lib/chef/application/solo.rb, line 170
    def initialize
      super
    end

### Public Instance Methods

reconfigure() click to toggle source
Calls superclass method Chef::Application#reconfigure

    # 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_application() click to toggle source

    # 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_application() click to toggle source

    # File lib/chef/application/solo.rb, line 204
    def setup_application
      Chef::Daemon.change_privilege
    end