llmongodb/sigterm.go

37 lines
496 B
Go
Raw Normal View History

2015-11-20 15:23:12 +01:00
// sigterm
package main
import (
"fmt"
"log"
2015-11-20 15:23:12 +01:00
"os"
"os/signal"
"syscall"
"time"
2015-11-20 15:23:12 +01:00
)
func kill() {
log.Printf("KILL %d\n", status)
fmt.Printf("KILL %d\n", status)
wg.Done()
count.DelWG()
done <- true
}
2015-11-20 15:23:12 +01:00
func exit() {
log.Printf("EXIT %d\n", status)
fmt.Printf("EXIT %d\n", status)
loop = false
time.AfterFunc(time.Second*20, kill)
2015-11-20 15:23:12 +01:00
}
func setTerm() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
exit()
}()
}