I have a simple Go server. Code below. server.go
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
I have an EC2 server with CodeDeploy agent and everything in place. All I am trying to do is, once I push and merge new code with master branch of my Github repo, CodeDeploy should deploy the revisions to my EC2 server In-Place and below is my appspec.yml (which is at the root of my repo)
appspec.yml
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/go/myproject
hooks:
AfterInstall:
- location: after-install.sh
runas: ubuntu
after-install.sh script below. Pretty simple, after the revision is deployed to myproject folder in EC2, cd into the folder and start the go server.
#!/bin/bash
cd $HOME/go/myproject
/usr/local/go/bin/go run server.go &
Problem: With the above, revisions are perfectly deployed and the server is started and I can hit the public dns on port 8080 from my browser and see the changes. However, CodeDeploy keeps running and never shows that deployment is completed.
Is there anything I should do for CodeDeploy to gracefully complete after starting the Go server?