llmongodb/sigterm.go

40 lines
535 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()
2016-12-20 15:37:32 +01:00
counter <- Counterchan{
tipo: "wg",
val: -1,
}
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()
}()
}