summaryrefslogtreecommitdiff
path: root/lib/chef/application/solo.rb
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-09-22 15:31:47 -0700
committerClaire McQuin <claire@getchef.com>2014-10-01 14:31:05 -0700
commit97b628a766d14a6a8fe6b3b2febb604a570e0cde (patch)
tree29f7f11b43250010a8e71c787c8d01eae0f1b97a /lib/chef/application/solo.rb
parent00ecc94e206da3c09cf5dac8d698deaba970d8b2 (diff)
downloadchef-97b628a766d14a6a8fe6b3b2febb604a570e0cde.tar.gz
Disable unforked interval runs.
Clarify error message. Move fork and interval logic to application (specs pending). Clean code logic, fix specs. Allow unforked client runs with daemonize or splay
Diffstat (limited to 'lib/chef/application/solo.rb')
-rw-r--r--lib/chef/application/solo.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index f0e578d5ef..cf7b5b4223 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -185,6 +185,8 @@ class Chef::Application::Solo < Chef::Application
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, '..'))
@@ -209,6 +211,22 @@ class Chef::Application::Solo < Chef::Application
end
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
+
+ private
+ def interval_run_chef_client
if Chef::Config[:daemonize]
Chef::Daemon.daemonize("chef-client")
end
@@ -244,8 +262,6 @@ class Chef::Application::Solo < Chef::Application
end
end
- private
-
def fetch_recipe_tarball(url, path)
Chef::Log.debug("Download recipes tarball from #{url} to #{path}")
File.open(path, 'wb') do |f|
@@ -254,4 +270,11 @@ class Chef::Application::Solo < Chef::Application
end
end
end
+
+ def unforked_interval_error_message
+ "Unforked chef-client interval runs are disabled in Chef 12." +
+ "\nConfiguration settings:" +
+ "#{"\n interval = #{Chef::Config[:interval]} seconds" if Chef::Config[:interval]}" +
+ "\nEnable chef-client interval runs by setting `:client_fork = true` in your config file or adding `--fork` to your command line options."
+ end
end