diff options
Diffstat (limited to 'lib/chef/application')
-rw-r--r-- | lib/chef/application/apply.rb | 18 | ||||
-rw-r--r-- | lib/chef/application/exit_code.rb | 8 | ||||
-rw-r--r-- | lib/chef/application/knife.rb | 4 | ||||
-rw-r--r-- | lib/chef/application/windows_service.rb | 59 | ||||
-rw-r--r-- | lib/chef/application/windows_service_manager.rb | 2 |
5 files changed, 43 insertions, 48 deletions
diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb index 3e3fb58448..d7f2359b02 100644 --- a/lib/chef/application/apply.rb +++ b/lib/chef/application/apply.rb @@ -200,16 +200,14 @@ class Chef::Application::Apply < Chef::Application end def run_application - begin - parse_options - run_chef_recipe - Chef::Application.exit! "Exiting", 0 - rescue SystemExit - raise - rescue Exception => e - Chef::Application.debug_stacktrace(e) - Chef::Application.fatal!("#{e.class}: #{e.message}", e) - end + parse_options + run_chef_recipe + Chef::Application.exit! "Exiting", 0 + rescue SystemExit + raise + rescue Exception => e + Chef::Application.debug_stacktrace(e) + Chef::Application.fatal!("#{e.class}: #{e.message}", e) end # Get this party started diff --git a/lib/chef/application/exit_code.rb b/lib/chef/application/exit_code.rb index 2c1298cf91..610a356a7c 100644 --- a/lib/chef/application/exit_code.rb +++ b/lib/chef/application/exit_code.rb @@ -198,12 +198,10 @@ class Chef end def notify_on_deprecation(message) - begin - Chef.deprecated(:exit_code, message) - rescue Chef::Exceptions::DeprecatedFeatureError + Chef.deprecated(:exit_code, message) + rescue Chef::Exceptions::DeprecatedFeatureError # Have to rescue this, otherwise this unhandled error preempts # the current exit code assignment. - end end def deprecation_warning @@ -222,7 +220,7 @@ class Chef def default_exit_code if normalization_disabled? || normalization_not_configured? - return DEPRECATED_RFC_062_EXIT_CODES[:DEPRECATED_FAILURE] + DEPRECATED_RFC_062_EXIT_CODES[:DEPRECATED_FAILURE] else VALID_RFC_062_EXIT_CODES[:GENERIC_FAILURE] end diff --git a/lib/chef/application/knife.rb b/lib/chef/application/knife.rb index c80d0245f1..521011348f 100644 --- a/lib/chef/application/knife.rb +++ b/lib/chef/application/knife.rb @@ -203,11 +203,11 @@ class Chef::Application::Knife < Chef::Application Chef::Log.error(fatal_message) if fatal_message begin - self.parse_options + parse_options rescue OptionParser::InvalidOption => e puts "#{e}\n" end - puts self.opt_parser + puts opt_parser puts Chef::Knife.list_commands exit exitcode diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index 2f1456ac45..7bc68a586d 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -183,39 +183,38 @@ class Chef # The chef client will be started in a new process. We have used shell_out to start the chef-client. # The log_location and config_file of the parent process is passed to the new chef-client process. # We need to add the --no-fork, as by default it is set to fork=true. - begin - Chef::Log.info "Starting chef-client in a new process" - # Pass config params to the new process - config_params = " --no-fork" - config_params += " -c #{Chef::Config[:config_file]}" unless Chef::Config[:config_file].nil? - # log_location might be an event logger and if so we cannot pass as a command argument - # but shed no tears! If the logger is an event logger, it must have been configured - # as such in the config file and chef-client will use that when no arg is passed here - config_params += " -L #{resolve_log_location}" if resolve_log_location.is_a?(String) - - # Starts a new process and waits till the process exits - - result = shell_out( - "chef-client.bat #{config_params}", - :timeout => Chef::Config[:windows_service][:watchdog_timeout], - :logger => Chef::Log - ) - Chef::Log.debug "#{result.stdout}" - Chef::Log.debug "#{result.stderr}" - rescue Mixlib::ShellOut::CommandTimeout => e - Chef::Log.error "chef-client timed out\n(#{e})" - Chef::Log.error(<<-EOF) + + Chef::Log.info "Starting chef-client in a new process" + # Pass config params to the new process + config_params = " --no-fork" + config_params += " -c #{Chef::Config[:config_file]}" unless Chef::Config[:config_file].nil? + # log_location might be an event logger and if so we cannot pass as a command argument + # but shed no tears! If the logger is an event logger, it must have been configured + # as such in the config file and chef-client will use that when no arg is passed here + config_params += " -L #{resolve_log_location}" if resolve_log_location.is_a?(String) + + # Starts a new process and waits till the process exits + + result = shell_out( + "chef-client.bat #{config_params}", + :timeout => Chef::Config[:windows_service][:watchdog_timeout], + :logger => Chef::Log + ) + Chef::Log.debug "#{result.stdout}" + Chef::Log.debug "#{result.stderr}" + rescue Mixlib::ShellOut::CommandTimeout => e + Chef::Log.error "chef-client timed out\n(#{e})" + Chef::Log.error(<<-EOF) Your chef-client run timed out. You can increase the time chef-client is given to complete by configuring windows_service.watchdog_timeout in your client.rb. EOF - rescue Mixlib::ShellOut::ShellCommandFailed => e - Chef::Log.warn "Not able to start chef-client in new process (#{e})" - rescue => e - Chef::Log.error e - ensure - # Once process exits, we log the current process' pid - Chef::Log.info "Child process exited (pid: #{Process.pid})" - end + rescue Mixlib::ShellOut::ShellCommandFailed => e + Chef::Log.warn "Not able to start chef-client in new process (#{e})" + rescue => e + Chef::Log.error e + ensure + # Once process exits, we log the current process' pid + Chef::Log.info "Child process exited (pid: #{Process.pid})" end def apply_config(config_file_path) diff --git a/lib/chef/application/windows_service_manager.rb b/lib/chef/application/windows_service_manager.rb index fd0ce0b174..5c572bc260 100644 --- a/lib/chef/application/windows_service_manager.rb +++ b/lib/chef/application/windows_service_manager.rb @@ -168,7 +168,7 @@ class Chef PAUSED = "paused" def service_exists? - return ::Win32::Service.exists?(@service_name) + ::Win32::Service.exists?(@service_name) end def take_action(action = nil, desired_state = nil) |