aws / aws-codedeploy-agent

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

Bug seen during deployment getcwd: cannot access parent directories: No such file or directory #339

Closed Ruchira-R closed 1 year ago

Ruchira-R commented 1 year ago

Version : Latest version of CodeDeploy Agent.

Machine VM : Centos 7 (Linux)

Deployment : In-place Error message : shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

This happens when I create a new directory to copy my deployment files(Created in the BeforeInstall hook) and I remove this directory in ApplicationStart hook.

NOTE : The steps actually are successfully executed and the deployment is successful. But, the logs show this error for every step executed in the specified hooks above.

t0shiii commented 1 year ago

@Ruchira-R Can you provide some more information? Version: Please provide the exact version of the agent. Here is the documentation on how to retrieve this info: doc

appspec: Is it possible for you to paste your whole appspec.yml file?

logs: Please provide the CodeDeploy agent logs or deployment logs which shows this error message. For information about how to retrieve this message please see this doc

Ruchira-R commented 1 year ago

@t0shiii Version : agent_version: OFFICIAL_1.4.1-2244_rpm

appspec : Has ApplicationStop, BeforeInstall, AfterInstall, ApplicationStart

All hooks only run shell scripts.

Currently, the ApplicationStop part is not running during the very first Deployment.

Logs

Logfile created on 2022-11-02 05:07:46 +0000 by logger.rb/41954 [2022-11-02 05:07:46.751] [d-B2BQPICUK]LifecycleEvent - BeforeInstall [2022-11-02 05:07:46.751] [d-B2BQPICUK]Script - before_install.sh [2022-11-02 05:07:46.771] [d-B2BQPICUK][stderr]shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory [2022-11-02 05:07:46.772] [d-B2BQPICUK][stderr]shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory [2022-11-02 05:07:46.803] [d-B2BQPICUK][stderr]shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory [2022-11-02 05:07:48.883] [d-B2BQPICUK]LifecycleEvent - AfterInstall [2022-11-02 05:07:48.883] [d-B2BQPICUK]Script - after_install.sh [2022-11-02 05:07:48.898] [d-B2BQPICUK][stderr]shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory [2022-11-02 05:07:48.898] [d-B2BQPICUK][stderr]shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory [2022-11-02 05:07:48.921] [d-B2BQPICUK][stderr]shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory [2022-11-02 05:07:48.924] [d-B2BQPICUK][stderr]chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

Also, the very first time I run the deployment, I only see it starting from Before Install, why does/did it not run the ApplicationStop hook? It's very weird.

DOES IT ASSUME THAT WE ARE INSTALLING THE APPLICATION THE FIRST TIME AND NOT UPDATING THE APPLICATION? (And so it doesn't run the ApplicationStop part?)

t0shiii commented 1 year ago

ApplicationStop does not run the first time a deployment is triggered for a host. This is by design since there is no application to stop the first time a deployment is run.

The error retrieving current directory: getcwd: cannot access parent directories: No such file or directory error is typically due to the current working directory no longer existing.

Please provide your full appspec.yml content.

Ruchira-R commented 1 year ago

@t0shiii I have runas: root, and also had sudo su in all of my scripts, maybe this was cause of the issue.

It is working as expected now.

I also had another doubt, how can I make sure the Deployment shows FAILURE, even if one of the instances that were undergoing deployment have FAILED?

Currently, I'm using "CodeDeployDefault.AllAtOnce", according to the documentation, it succeeds even if one of the instances has successfully been upgraded.

I know that using "CodeDeployDefault.OneAtATime" will help but it will still show SUCCESS if the deployment to the last instance fails, is there any way I can override this feature?

I just want to STOP/make sure the deployment shows FAILURE, if any of the instances fail to upgrade during the deployment.

I have a limited amount of instances running (Using EC2/On-Prem Deployment), therefore, this is expected result needed, is there any alternative?

aj-aws commented 1 year ago

@Ruchira-R Thank you for the question. We will close this issue as the original question has been resolved. Please open a new issue re: your deployment config question.