1

I'm trying to deploy a simple golang webserver to EC2 using CodeDeploy. Deployment fails with following error {\"error_code\":6,\"script_name\":\"scripts/start.sh\",\"message\":\"Script at specified location: scripts/start.sh failed to close STDOUT\". CodeDeploy related files:

appspec.yml

version: 0.0

os: linux

files:
  - source: /main.go
    destination: /app/
  - source: /index.html
    destination: /app/
  - source: /config.json
    destination: /app/
  - source: /webserver.log
    destination: /app/

hooks:
  BeforeInstall:
    - location: scripts/cleanup.sh
      timeout: 180
      runas: root
  AfterInstall:
    - location: scripts/build.sh
      timeout: 180
      runas: root
  ApplicationStart:
    - location: scripts/start.sh
      timeout: 180
      runas: root

scripts/cleanup.sh

sudo rm /app -rf
sudo mkdir /app
sudo chown -R ec2-user:ec2-user /app

sudo yum update -y
sudo yum install -y golang

scripts/build.sh

go build -o /app/webserver /app/main.go

scripts/start.sh

/app/webserver &

I imagine it's related to how I start the server, but I'm no good with Linux intricacies so more detailed explanation would be highly appreciated.

Full webserver source code can be found in github.

1 Answer 1

6

I think it's related to stdout, stderr, and stdin:

Add below string before &

/dev/null 2> /dev/null < /dev/null

The source

Sign up to request clarification or add additional context in comments.

3 Comments

Hi, I'm getting the STDOUT error on my application_start.sh. Where would you recommend adding this line in my code? #!/bin/sh cd /home/ec2-user npm run start&
before & and after start I think.
You've just helped me finish my 8 day quest to completing my first Code Commit to EC2 instance. Thanks a lot for helping!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.