Skip to content

Commit 01fb217

Browse files
authored
Merge pull request #843 from cboitel/graceful-shutdown
fix: gracefully shutdown servers on int/term signals
2 parents afe1b37 + 19748e0 commit 01fb217

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cmd/mokapi/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import (
44
"context"
55
"mokapi/pkg/cmd/mokapi"
66
"os"
7+
"os/signal"
8+
"syscall"
79
)
810

911
func main() {
12+
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
13+
defer stop()
14+
1015
cmd := mokapi.NewCmdMokapi()
11-
err := cmd.ExecuteWithContext(context.Background())
16+
err := cmd.ExecuteWithContext(ctx)
1217
if err != nil {
1318
_, _ = os.Stderr.Write([]byte(err.Error()))
1419
}

0 commit comments

Comments
 (0)