Improve startup/shutdown logging

This commit is contained in:
Torjus Håkestad 2021-04-10 08:16:59 +02:00
parent e93d2d2c8b
commit 5ec1d11ea7

View File

@ -3,10 +3,12 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"net/http"
"os" "os"
"os/signal" "os/signal"
"time" "time"
"github.com/gliderlabs/ssh"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"github.uio.no/torjus/apiary" "github.uio.no/torjus/apiary"
"github.uio.no/torjus/apiary/config" "github.uio.no/torjus/apiary/config"
@ -86,18 +88,24 @@ func ActionServe(c *cli.Context) error {
// Handle interrupt // Handle interrupt
go func() { go func() {
<-interruptChan <-interruptChan
fmt.Println("Got interrupt. Shutting down.") loggers.rootLogger.Info("Interrupt received, shutting down")
serversCancel() serversCancel()
}() }()
// Start ssh server // Start ssh server
go func() { 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 // Start web server
go func() { 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() { go func() {