Class: Chef::Application::Client
- Inherits:
-
Chef::Application
- Object
- Chef::Application
- Chef::Application::Client
- Defined in:
- lib/chef/application/client.rb
Instance Method Summary collapse
- #configure_logging ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#reconfigure ⇒ Object
Reconfigure the chef client Re-open the JSON attributes and load them into the node.
-
#run_application ⇒ Object
Run the chef client, optionally daemonizing or looping at intervals.
- #setup_application ⇒ Object
Methods inherited from Chef::Application
#configure_chef, exit!, fatal!, #run
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
141 142 143 144 145 146 |
# File 'lib/chef/application/client.rb', line 141 def initialize super @chef_client = nil @chef_client_json = nil end |
Instance Method Details
#configure_logging ⇒ Object
192 193 194 195 196 |
# File 'lib/chef/application/client.rb', line 192 def configure_logging super Chef::Log.verbose = Chef::Config[:verbose_logging] Mixlib::Authentication::Log.logger = Ohai::Log.logger = Chef::Log.logger end |
#reconfigure ⇒ Object
Reconfigure the chef client Re-open the JSON attributes and load them into the node
150 151 152 153 154 155 156 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 |
# File 'lib/chef/application/client.rb', line 150 def reconfigure super Chef::Config[:chef_server_url] = config[:chef_server_url] if config.has_key? :chef_server_url if Chef::Config[:daemonize] Chef::Config[:interval] ||= 1800 end if Chef::Config[:once] Chef::Config[:interval] = nil Chef::Config[:splay] = nil 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.}", 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., 2) end end end |
#run_application ⇒ Object
Run the chef client, optionally daemonizing or looping at intervals.
203 204 205 206 207 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 243 244 245 |
# File 'lib/chef/application/client.rb', line 203 def run_application if Chef::Config[:version] puts "Chef version: #{::Chef::VERSION}" end 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 @chef_client = Chef::Client.new(@chef_client_json) @chef_client_json = nil @chef_client.run @chef_client = nil 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}\n#{e.backtrace.join("\n")}") Chef::Log.error("Sleeping for #{Chef::Config[:interval]} seconds before trying again") sleep Chef::Config[:interval] retry else raise end ensure GC.start end end end |
#setup_application ⇒ Object
198 199 200 |
# File 'lib/chef/application/client.rb', line 198 def setup_application Chef::Daemon.change_privilege end |