1
votes

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

1 Answers

3
votes

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

Add below string before &

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

The source