aws / aws-codedeploy-agent

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

Codedeploy-agent error when run in amazon linux instance #108

Closed marcoblos closed 7 years ago

marcoblos commented 7 years ago

When I create a new deploy in AWSCodeDeploy with GitHub I receive this fail message:

Error CodeScriptFailed
Script Namescripts/stop_server.sh
MessageScript at specified location: scripts/stop_server.sh run as user ubuntu failed with exit code 1
Log TailLifecycleEvent - ApplicationStop
Script - scripts/stop_server.sh
[stderr]su: user ubuntu does not exist

But, my instance is an Amazon Linux Instance and don't have a ubuntu user, anybody know anything about this?

The script that a try to run is:

# scripts/stop_server.sh
#!/bin/bash
forever stop .

My appspec.yml file:

version: 0.0
os: linux
files:
   - source: /
     destination: /home/ec2-user
hooks:
  AfterInstall:
    - location: scripts/install_dependencies.sh
      timeout: 5
      runas: root
  ApplicationStart:
    - location: scripts/start_server.sh
      timeout: 5
      runas: root
  ApplicationStop:
    - location: scripts/stop_server.sh
      timeout: 5
      runas: root

Codedeploy-agent version agent_version: OFFICIAL_1.0-1.1095_rpm

Error log:

2017-04-23 23:18:18 INFO  [codedeploy-agent(2620)]: Version file found in /opt/codedeploy-agent/.version.
2017-04-23 23:18:18 INFO  [codedeploy-agent(2620)]: [Aws::CodeDeployCommand::Client 200 0.049676 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":4,\"script_name\":\"scripts/stop_server.sh\",\"message\":\"Script at specified location: scripts/stop_server.sh run as user ubuntu failed with exit code 1\",\"log\":\"LifecycleEvent - ApplicationStop\\nScript - scripts/stop_server.sh\\n[stderr]su: user ubuntu does not exist\\n\"}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS9zYS1lYXN0LTEvUHJvZC9hcm46YXdzOnNkczpzYS1lYXN0LTE6NzE3MjUzNzgxMDk3OmRlcGxveW1lbnQvZC05SFlVVlRSWUsiLCJob3N0SWQiOiJhcm46YXdzOmVjMjpzYS1lYXN0LTE6NzE3MjUzNzgxMDk3Omluc3RhbmNlL2ktMDAyYmE1OTMyYTIyOTRjODgiLCJjb21tYW5kTmFtZSI6IkFwcGxpY2F0aW9uU3RvcCIsImNvbW1hbmRQb3NpdGlvbiI6MSwiY29tbWFuZEF0dGVtcHQiOjF9XQ==")

2017-04-23 23:18:18 ERROR [codedeploy-agent(2620)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - Script at specified location: scripts/stop_server.sh run as user ubuntu failed with exit code 1 - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:158:in `execute_script'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:115:in `block (2 levels) in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:103:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:103:in `block in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:173:in `create_script_log_file_if_needed'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:101:in `execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:141:in `block (3 levels) in map'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:129:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:129:in `block (2 levels) in map'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:62:in `execute_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:132:in `process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:65:in `perform'
/opt/codedeploy-agent/lib/instance_agent/agent/base.rb:28:in `run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:38:in `block in run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:37:in `run'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:70:in `block in run_with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:69:in `run_with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:33:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `loop'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:206:in `block in spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:204:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:204:in `spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:196:in `block in spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:195:in `times'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:195:in `spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:134:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:37:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:36:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:36:in `start'
/opt/codedeploy-agent/bin/../lib/codedeploy-agent.rb:41:in `block (2 levels) in <main>'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `execute'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:262:in `block in call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:69:in `run'
/opt/codedeploy-agent/bin/../lib/codedeploy-agent.rb:88:in `<main>'
2017-04-23 23:18:24 INFO  [codedeploy-agent(2620)]: Version file found in /opt/codedeploy-agent/.version.
2017-04-23 23:19:24 INFO  [codedeploy-agent(2620)]: [Aws::CodeDeployCommand::Client 200 60.450671 0 retries] poll_host_command(host_identifier:"arn:aws:ec2:sa-east-1:717253781097:instance/i-002ba5932a2294c88")

2017-04-23 23:19:25 INFO  [codedeploy-agent(2620)]: Version file found in /opt/codedeploy-agent/.version.
2017-04-23 23:20:25 INFO  [codedeploy-agent(2620)]: [Aws::CodeDeployCommand::Client 200 60.220637 0 retries] poll_host_command(host_identifier:"arn:aws:ec2:sa-east-1:717253781097:instance/i-002ba5932a2294c88")
feverLu commented 7 years ago

Could you double check the following things?

marcoblos commented 7 years ago

First check:

$ cat /etc/issue
Amazon Linux AMI release 2017.03

$ uname -a
Linux ip-172-31-26-68 4.9.20-11.31.amzn1.x86_64 #1 SMP Thu Apr 13 01:53:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Second check:

My first contact with CodeDeploy was last saturday and never successful run before.

@feverLu Could I do some other test?

marcoblos commented 7 years ago

I resolved the problem deleting the application and create a new one. I don't know what happen in agent to make this error.

Thanks for help.