class Kafo::ExitHandler
Attributes
Public Class Methods
Source
# File lib/kafo/exit_handler.rb, line 5 def initialize @cleanup_paths = [] @exit_code = 0 end
Public Instance Methods
Source
# File lib/kafo/exit_handler.rb, line 44 def cleanup # make sure default values are removed from /tmp (self.cleanup_paths + ['/tmp/default_values.yaml']).each do |file| logger.debug "Cleaning #{file}" FileUtils.rm_rf(file) end end
Source
# File lib/kafo/exit_handler.rb, line 10 def error_codes @error_codes ||= { :invalid_system => 20, :invalid_values => 21, :manifest_error => 22, :no_answer_file => 23, :unknown_module => 24, :defaults_error => 25, :unset_scenario => 26, :scenario_error => 27, :missing_argument => 28, :insufficient_permissions => 29, :puppet_version_error => 30 } end
Source
# File lib/kafo/exit_handler.rb, line 26 def exit(code, &block) @exit_code = translate_exit_code(code) block.call if block KafoConfigure.hooking.execute(:pre_exit, log_stage: false) logger.debug "Exit with status code: #{@exit_code} (signal was #{code})" cleanup Kernel.exit(@exit_code) end
Source
# File lib/kafo/exit_handler.rb, line 52 def register_cleanup_path(path) self.cleanup_paths<< path end
Source
# File lib/kafo/exit_handler.rb, line 35 def translate_exit_code(code) return code if code.is_a?(Integer) if error_codes.has_key?(code) return error_codes[code] else raise "Unknown code #{code}" end end
Private Instance Methods
Source
# File lib/kafo/exit_handler.rb, line 58 def logger @logger ||= KafoConfigure.logger end