diff --git a/cmd/root.go b/cmd/root.go index c89dccb..3ebac9d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,10 +24,8 @@ type rootCli struct { func Run() { err := godotenv.Load() - if err != nil { - if !errors.Is(err, os.ErrNotExist) { - log.Fatalf("failed to read env: %s", err) - } + if err != nil && !errors.Is(err, os.ErrNotExist) { + log.Fatalf("failed to read env: %s", err) } rootCliApp := &rootCli{} diff --git a/cmd/server.go b/cmd/server.go index 18b05bc..31286ce 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/signal" + "syscall" "time" "github.com/theruziev/starter/internal/app/server" @@ -19,17 +20,16 @@ type serverCli struct { func (s *serverCli) Run(cliCtx *contextCli) error { logger := logx.NewLogger(cliCtx.LogLevel, cliCtx.IsDebug) ctx := logx.WithLogger(context.Background(), logger) - ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill) + ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM) defer cancel() cl := closer.NewCloser() go func() { <-ctx.Done() - logger.Warnf("graceful shutdown") + logger.Warn("graceful shutdown initiated") closeCtx, closeCancel := context.WithTimeout(context.Background(), 10*time.Second) defer closeCancel() - err := cl.Close(closeCtx) - if err != nil { + if err := cl.Close(closeCtx); err != nil { logger.Errorf("failed to close server: %s", err) } }()