-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreload.go
48 lines (43 loc) · 954 Bytes
/
reload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"os"
"syscall"
"time"
"github.com/mapleque/proxy/service"
)
func (this *watcher) sendReloadSignal() {
this.doReloadLazy()
}
func (this *watcher) doReloadLazy() {
if this.reloadLazySeconds <= 0 {
this.doReload()
return
}
if this.reloadTimer == nil {
this.logger.Info(fmt.Sprintf("do reload lazy after %ds", this.reloadLazySeconds))
this.reloadTimer = time.AfterFunc(
time.Duration(this.reloadLazySeconds)*time.Second,
func() {
this.doReload()
this.reloadTimer = nil
},
)
} else {
this.logger.Debug("lazy reloading")
}
}
func (this *watcher) doReload() {
pid, err := service.ReadPidFromFile(this.pidFile)
if err != nil {
this.logger.Error("read pid file error", err)
return
}
process, err := os.FindProcess(pid)
if err != nil {
this.logger.Error("find process error", pid, err)
return
}
process.Signal(syscall.SIGHUP)
this.logger.Info("send reload signal success")
}