aws / aws-codedeploy-agent

Host Agent for AWS CodeDeploy
https://aws.amazon.com/codedeploy
Apache License 2.0
328 stars 188 forks source link

[Error] AL2023 - max_revisions - Error deleting directories #377

Open ygorth opened 12 months ago

ygorth commented 12 months ago

Specs:

OS: Amazon Linux 2023
codedeploy-agent: OFFICIAL_1.6.0-49_rpm.
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
aws region : us-east-1

Please review this log generated by the codedeploy-agent, which attempted to delete previous deployment folders based on the specified max_revisions number but encountered an error.

2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: Successfully parsed the deployment spec
2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: Creating deployment root directory /opt/codedeploy-agent/deployment-root/1b1cc9e8-aaef-43e7-9bc8-988e6649cf6e/d-8YGI5LZJ1
2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandExecutor: Delete Files ["/opt/codedeploy-agent/deployment-root/1b1cc9e8-aaef-43e7-9bc8-988e6649cf6e/d-C6WOEPZJ1"]
2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::LinuxUtil: Dirs to delete: ["/opt/codedeploy-agent/deployment-root/1b1cc9e8-aaef-43e7-9bc8-988e6649cf6e/d-C6WOEPZJ1"]
2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::LinuxUtil: Deleting dir: /opt/codedeploy-agent/deployment-root/1b1cc9e8-aaef-43e7-9bc8-988e6649cf6e/d-C6WOEPZJ1
2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::LinuxUtil: Command status: pid 10890 exit 2
2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::LinuxUtil: Command output: 
2023-09-07T19:50:40 ERROR [codedeploy-agent(8798)]: InstanceAgent::LinuxUtil: Error deleting directories: 2
2023-09-07T19:50:40 DEBUG [codedeploy-agent(8798)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" 
2023-09-07T19:50:40 INFO  [codedeploy-agent(8798)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.6.0-49_rpm.
2023-09-07T19:50:40 INFO  [codedeploy-agent(8798)]: [Aws::CodeDeployCommand::Client 200 0.050493 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":5,\"script_name\":\"\",\"message\":\"Error deleting directories: 2\",\"log\":\"\"}"},host_command_identifier:"eyJiYXRjaElkIjoiYzQzYTYwY2NiNmU5MzQ0ZWI2OGQ2NjY1N2RjZjZjNTYvcHVibGljMDE3IiwiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvcHJvZC9vcnBoZXVzOnB1YmxpYzAwMy85NDYwNDM5MzkyMzY6ZC04WUdJNUxaSjEiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6OTQ2MDQzOTM5MjM2Omluc3RhbmNlL2ktMDU1ZDBjMDlkZjA2NjcxYTQiLCJjb21tYW5kSWQiOiJBcG9sbG9EZXBsb3lDb250cm9sU2VydmljZXxhcm46YXdzOmVjMjp1cy1lYXN0LTE6OTQ2MDQzOTM5MjM2Omluc3RhbmNlL2ktMDU1ZDBjMDlkZjA2NjcxYTR8MnwwIiwiY29tbWFuZE5hbWUiOiJEb3dubG9hZEJ1bmRsZSIsImNvbW1hbmRJbmRleCI6MiwiYXR0ZW1wdEluZGV4IjoxfQ==")  

2023-09-07T19:50:40 ERROR [codedeploy-agent(8798)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: RuntimeError - Error deleting directories: 2 - /opt/codedeploy-agent/lib/instance_agent/platform/linux_util.rb:99:in `delete_folder'
/opt/codedeploy-agent/lib/instance_agent/platform/linux_util.rb:85:in `block in delete_dirs_command'
/opt/codedeploy-agent/lib/instance_agent/platform/linux_util.rb:83:in `each'
/opt/codedeploy-agent/lib/instance_agent/platform/linux_util.rb:83:in `delete_dirs_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:574:in `cleanup_old_archives'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:124:in `block in <class:CommandExecutor>'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:115:in `execute_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:137:in `process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:119:in `acknowledge_and_process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:99:in `block in perform'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:363:in `run_task'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `block (3 levels) in create_worker'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `loop'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `block (2 levels) in create_worker'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `catch'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block in create_worker'
/opt/codedeploy-agent/vendor/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
2023-09-07T19:50:40 WARN  [codedeploy-agent(8798)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" 
2023-09-07T19:50:40 INFO  [codedeploy-agent(8798)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.6.0-49_rpm.
2023-09-07T19:50:40 INFO  [codedeploy-agent(8798)]: [Aws::CodeDeployCommand::Client 200 0.024591 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":5,\"script_name\":\"\",\"message\":\"Error deleting directories: 2\",\"log\":\"\"}"},host_command_identifier:"eyJiYXRjaElkIjoiYzQzYTYwY2NiNmU5MzQ0ZWI2OGQ2NjY1N2RjZjZjNTYvcHVibGljMDE3IiwiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvcHJvZC9vcnBoZXVzOnB1YmxpYzAwMy85NDYwNDM5MzkyMzY6ZC04WUdJNUxaSjEiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6OTQ2MDQzOTM5MjM2Omluc3RhbmNlL2ktMDU1ZDBjMDlkZjA2NjcxYTQiLCJjb21tYW5kSWQiOiJBcG9sbG9EZXBsb3lDb250cm9sU2VydmljZXxhcm46YXdzOmVjMjp1cy1lYXN0LTE6OTQ2MDQzOTM5MjM2Omluc3RhbmNlL2ktMDU1ZDBjMDlkZjA2NjcxYTR8MnwwIiwiY29tbWFuZE5hbWUiOiJEb3dubG9hZEJ1bmRsZSIsImNvbW1hbmRJbmRleCI6MiwiYXR0ZW1wdEluZGV4IjoxfQ==")  

2023-09-07T19:50:41 DEBUG [codedeploy-agent(8798)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PollHostCommand:
2023-09-07T19:50:41 INFO  [codedeploy-agent(8798)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.6.0-49_rpm.
ygorth commented 12 months ago

I've updated /usr/lib/systemd/system/codedeploy-agent.service removing the option "-a" from /bin/bash, and it is now deleting the folders w/o raising errors.

New codedeploy-agent.service w/o "-a":

$ cat /usr/lib/systemd/system/codedeploy-agent.service
[Unit]
Description=AWS CodeDeploy Host Agent

[Service]
Type=forking
ExecStart=/bin/bash -c '[ -f /etc/profile ] && source /etc/profile; /opt/codedeploy-agent/bin/codedeploy-agent start'
ExecStop=/opt/codedeploy-agent/bin/codedeploy-agent stop
RemainAfterExit=no
Restart=on-failure

# Uncomment the following line to run the agent as the codedeploy user
# Note: The user must first exist on the system
#User=codedeploy

[Install]
WantedBy=multi-user.target
BaconFries commented 11 months ago

I was trying to go from AL2 to AL2023 and having an issue with any bash script in the appspec. Removing the -a like you did worked. [stderr]bash: _parse_usage: line 16: syntax error near unexpected token ('

ygorth commented 11 months ago

That's correct @BaconFries. I will run some tests and push a PR later this week.