feat: exit cleanly on sigterm/siginterr
This commit is contained in:
parent
8742f901b8
commit
3b9d475e89
1 changed files with 16 additions and 0 deletions
16
main.go
16
main.go
|
@ -5,7 +5,9 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
)
|
)
|
||||||
|
@ -40,6 +42,20 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *asDemon {
|
if *asDemon {
|
||||||
|
// exit cleanly on ctrl-C or kill
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
for range c {
|
||||||
|
// dump history to file so that other apps can query it
|
||||||
|
err = write(history, histfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
persist := !*noPersist
|
persist := !*noPersist
|
||||||
if err := listen(history, histfile, persist, *max); err != nil {
|
if err := listen(history, histfile, persist, *max); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in a new issue