增加 对信号的处理
This commit is contained in:
parent
14ba79c2b3
commit
a76d4cfe6c
17
fileboy.go
17
fileboy.go
@ -6,9 +6,11 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"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 {
|
||||
return projectFolder + "/" + filegirlYamlName
|
||||
}
|
||||
@ -341,5 +357,6 @@ func main() {
|
||||
if err != nil {
|
||||
logAndExit(err)
|
||||
}
|
||||
signalHandler()
|
||||
parseArgs()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user