From 5ec1d11ea76b41133684046eeb54f867aed24271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 10 Apr 2021 08:16:59 +0200 Subject: [PATCH] Improve startup/shutdown logging --- cmd/apiary.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/apiary.go b/cmd/apiary.go index 13db81f..bedc9ea 100644 --- a/cmd/apiary.go +++ b/cmd/apiary.go @@ -3,10 +3,12 @@ package main import ( "context" "fmt" + "net/http" "os" "os/signal" "time" + "github.com/gliderlabs/ssh" "github.com/urfave/cli/v2" "github.uio.no/torjus/apiary" "github.uio.no/torjus/apiary/config" @@ -86,18 +88,24 @@ func ActionServe(c *cli.Context) error { // Handle interrupt go func() { <-interruptChan - fmt.Println("Got interrupt. Shutting down.") + loggers.rootLogger.Info("Interrupt received, shutting down") serversCancel() }() // Start ssh server go func() { - hs.ListenAndServe() + loggers.rootLogger.Info("Starting SSH server") + if err := hs.ListenAndServe(); err != nil && err != ssh.ErrServerClosed { + loggers.rootLogger.Warnw("SSH server returned error", "error", err) + } }() // Start web server go func() { - web.ListenAndServe() + loggers.rootLogger.Info("Starting web server") + if err := web.ListenAndServe(); err != nil && err != http.ErrServerClosed { + loggers.rootLogger.Warnw("Web server returned error", "error", err) + } }() go func() {