增加 对信号的处理

master
dengsgo 2020-07-19 18:06:24 +08:00
parent 14ba79c2b3
commit a76d4cfe6c
1 changed files with 17 additions and 0 deletions

View File

@ -6,9 +6,11 @@ import (
"log" "log"
"math/rand" "math/rand"
"os" "os"
"os/signal"
"path" "path"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"gopkg.in/fsnotify/fsnotify.v1" "gopkg.in/fsnotify/fsnotify.v1"
@ -319,6 +321,20 @@ func parseArgs() {
} }
} }
func signalHandler() {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
if taskMan != nil && taskMan.cmd != nil && taskMan.cmd.Process != nil {
if err := taskMan.cmd.Process.Kill(); err != nil {
logError("stopping the process failed: PID:", taskMan.cmd.ProcessState.Pid(), ":", err)
}
}
os.Exit(0)
}()
}
func getFileGirlPath() string { func getFileGirlPath() string {
return projectFolder + "/" + filegirlYamlName return projectFolder + "/" + filegirlYamlName
} }
@ -341,5 +357,6 @@ func main() {
if err != nil { if err != nil {
logAndExit(err) logAndExit(err)
} }
signalHandler()
parseArgs() parseArgs()
} }