Skip to content

Commit

Permalink
feat(Docker): add healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
go-compile committed Jul 17, 2023
1 parent 855bcbd commit 96da60a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

WORKDIR /app

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD [ "localrelay", "status" ]

CMD ["/usr/bin/localrelay", "start-service-daemon"]
33 changes: 16 additions & 17 deletions cmd/localrelay/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"os"
"sort"
"strconv"
"time"
Expand All @@ -12,32 +13,30 @@ import (
)

func relayStatus() error {
// make terminal raw to allow the use of colour on windows terminals
current, _ := console.ConsoleFromFile(os.Stdout)
// NOTE: Docker healthchecks will panic "provided file is not a console"

if current != nil {
defer current.Reset()
}

if current != nil {
if err := current.SetRaw(); err != nil {
log.Println(err)
}
}

// we don't set terminal to raw here because print statements don't use
// carriage returns
s, err := serviceStatus()
if err != nil {

// make terminal raw to allow the use of colour on windows terminals
current := console.Current()

if err := current.SetRaw(); err != nil {
log.Fatal(err)
}

fmt.Printf("Daemon: \x1b[31m [OFFLINE] \x1b[0m\r\n")
fmt.Println(err)
current.Reset()

return nil
}

// make terminal raw to allow the use of colour on windows terminals
current := console.Current()
defer current.Reset()

if err := current.SetRaw(); err != nil {
log.Fatal(err)
// exit with error
os.Exit(1)
}

fmt.Printf("\r\nDaemon: \x1b[102m\x1b[30m [RUNNING] \x1b[0m\r\n")
Expand Down

0 comments on commit 96da60a

Please sign in to comment.