summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-08 01:44:58 +0800
committerKeuin <[email protected]>2022-09-08 01:44:58 +0800
commitaced234f80489f10e678cbe8ab2d44fe50c8e376 (patch)
tree8542f8fc09b31288f048bdf655bb3bce3b82d4ca /main.go
parent493ad1a723f9ade3bd049b156f0dc4d194f8fd3e (diff)
Correctly handle signals on exit.
Diffstat (limited to 'main.go')
-rw-r--r--main.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/main.go b/main.go
index dc50251..db58eca 100644
--- a/main.go
+++ b/main.go
@@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"sync"
+ "syscall"
)
var globalConfig *GlobalConfig
@@ -131,14 +132,24 @@ func main() {
go recording.RunTask(ctx, &wg, &task)
}
- // listen Ctrl-C
- chSigInt := make(chan os.Signal)
- signal.Notify(chSigInt, os.Interrupt)
+ // listen on stop signals
+ chSigStop := make(chan os.Signal)
+ signal.Notify(chSigStop,
+ syscall.SIGHUP,
+ syscall.SIGINT,
+ syscall.SIGTERM)
go func() {
- <-chSigInt
+ <-chSigStop
cancelTasks()
}()
+ chSigQuit := make(chan os.Signal)
+ signal.Notify(chSigQuit, syscall.SIGQUIT)
+ go func() {
+ <-chSigQuit
+ os.Exit(0)
+ }()
+
// block main goroutine on task goroutines
wg.Wait()
}