Class: InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor
- Inherits:
-
Object
- Object
- InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor
- Defined in:
- lib/instance_agent/plugins/codedeploy/hook_executor.rb
Constant Summary collapse
- LAST_SUCCESSFUL_DEPLOYMENT =
"OldOrIgnore"- CURRENT =
"New"
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(arguments = {}) ⇒ HookExecutor
constructor
A new instance of HookExecutor.
Constructor Details
#initialize(arguments = {}) ⇒ HookExecutor
Returns a new instance of HookExecutor.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/instance_agent/plugins/codedeploy/hook_executor.rb', line 63 def initialize(arguments = {}) #check arguments raise "Lifecycle Event Required " if arguments[:lifecycle_event].nil? raise "Deployment ID required " if arguments[:deployment_id].nil? raise "Deployment Root Directory Required " if arguments[:deployment_root_dir].nil? raise "App Spec Path Required " if arguments[:app_spec_path].nil? raise "Application name required" if arguments[:application_name].nil? raise "Deployment Group name required" if arguments[:deployment_group_name].nil? @lifecycle_event = arguments[:lifecycle_event] @deployment_id = arguments[:deployment_id] @application_name = arguments[:application_name] @deployment_group_name = arguments[:deployment_group_name] select_correct_deployment_root_dir(arguments[:deployment_root_dir], arguments[:last_successful_deployment_dir]) return if @deployment_root_dir.nil? @deployment_archive_dir = File.join(@deployment_root_dir, 'deployment-archive') @app_spec_path = arguments[:app_spec_path] parse_app_spec @hook_logging_mutex = Mutex.new @script_log = ScriptLog.new @child_envs={'LIFECYCLE_EVENT' => @lifecycle_event.to_s, 'DEPLOYMENT_ID' => @deployment_id.to_s, 'APPLICATION_NAME' => @application_name, 'DEPLOYMENT_GROUP_NAME' => @deployment_group_name} end |
Instance Method Details
#execute ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/instance_agent/plugins/codedeploy/hook_executor.rb', line 89 def execute return if @app_spec.nil? if (hooks = @app_spec.hooks[@lifecycle_event]) && !hooks.empty? create_script_log_file_if_needed do |script_log_file| log_script("LifecycleEvent - " + @lifecycle_event + "\n", script_log_file) hooks.each do |script| if(!File.exist?(script_absolute_path(script))) raise ScriptError.new(ScriptError::SCRIPT_MISSING_CODE, script.location, @script_log), 'Script does not exist at specified location: ' + script.location elsif(!InstanceAgent::Platform.util.script_executable?(script_absolute_path(script))) log :warn, 'Script at specified location: ' + script.location + ' is not executable. Trying to make it executable.' begin FileUtils.chmod("+x", script_absolute_path(script)) rescue raise ScriptError.new(ScriptError::SCRIPT_EXECUTABILITY_CODE, script.location, @script_log), 'Unable to set script at specified location: ' + script.location + ' as executable' end end begin execute_script(script, script_log_file) rescue Timeout::Error raise ScriptError.new(ScriptError::SCRIPT_TIMED_OUT_CODE, script.location, @script_log), 'Script at specified location: ' +script.location + ' failed to complete in '+script.timeout.to_s+' seconds' end end end end @script_log.log end |