增加 pid文件进程感知
This commit is contained in:
parent
7c6f8f910b
commit
c5f0649ab5
@ -48,3 +48,9 @@ func stopDaemon() error {
|
||||
os.Remove(getPidFile())
|
||||
return nil
|
||||
}
|
||||
|
||||
func stopSelf() {
|
||||
pid := os.Getpid()
|
||||
os.Remove(getPidFile())
|
||||
_ = exec.Command("kill", strconv.Itoa(pid)).Run()
|
||||
}
|
||||
|
@ -200,6 +200,15 @@ func initWatcher() {
|
||||
}
|
||||
|
||||
func watchChangeHandler(event fsnotify.Event) {
|
||||
// stop the fileboy daemon process when the .fileboy.pid file is changed
|
||||
if event.Name == getPidFile() &&
|
||||
(event.Op == fsnotify.Remove ||
|
||||
event.Op == fsnotify.Write ||
|
||||
event.Op == fsnotify.Rename) {
|
||||
logUInfo("exit daemon process")
|
||||
stopSelf()
|
||||
return
|
||||
}
|
||||
if event.Op != fsnotify.Create && event.Op != fsnotify.Rename {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user