summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-05-22 00:26:30 +0300
committerPaul Buetow <paul@buetow.org>2023-05-22 00:26:30 +0300
commit688ac52705c2e4bd015e8f369969de6a91e26d80 (patch)
treede2f160b3ffaf750c60585f59257045d7dda3c14 /cmd
parentbb79f9f50a89507fb7db6d1d4c62630e431952f9 (diff)
catch signals for shutdown
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gorum/main.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/cmd/gorum/main.go b/cmd/gorum/main.go
index 223da9d..e39f620 100644
--- a/cmd/gorum/main.go
+++ b/cmd/gorum/main.go
@@ -4,6 +4,10 @@ import (
"context"
"flag"
"fmt"
+ "log"
+ "os"
+ "os/signal"
+ "syscall"
"codeberg.org/snonux/gorum/internal"
)
@@ -21,8 +25,24 @@ func main() {
return
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := contextWithSignal()
defer cancel()
- internal.Run(ctx, *configFile)
+ internal.Start(ctx, *configFile)
+
+ <-ctx.Done()
+ log.Println("Good bye!")
+}
+
+func contextWithSignal() (context.Context, context.CancelFunc) {
+ ctx, cancel := context.WithCancel(context.Background())
+
+ go func() {
+ ch := make(chan os.Signal)
+ signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
+ <-ch
+ cancel()
+ }()
+
+ return ctx, cancel
}