Skip to content

Instantly share code, notes, and snippets.

@manhdaovan
Last active July 3, 2023 05:43
Show Gist options
  • Save manhdaovan/b60ce1de6164cfea8e675064dbdc38e9 to your computer and use it in GitHub Desktop.
Save manhdaovan/b60ce1de6164cfea8e675064dbdc38e9 to your computer and use it in GitHub Desktop.

Revisions

  1. manhdaovan revised this gist Jul 3, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion entry.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    cd /app
    ./test_gracefulMaMak
    ./test_graceful
  2. manhdaovan created this gist Jul 3, 2023.
    7 changes: 7 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    FROM alpine:latest

    WORKDIR /app

    COPY . /app

    ENTRYPOINT [ "ash", "entry.sh" ]
    9 changes: 9 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    build-app:
    GOOS=linux go build -o test_graceful main.go && \
    chmod +x test_graceful

    build-image: build-app
    docker build -t test_graceful .

    run-app-on-docker:
    docker run -it test_graceful
    2 changes: 2 additions & 0 deletions entry.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    cd /app
    ./test_gracefulMaMak
    18 changes: 18 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    package main

    import (
    "fmt"
    "os"
    "os/signal"
    "syscall"
    )

    func main() {
    fmt.Println("main started")
    shutdown := make(chan os.Signal, 2)
    signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
    select {
    case s := <-shutdown:
    fmt.Println("shutdown server by received signal:", s.String())
    }
    }