Remove pid file

pull/80/head
Doflatango 2018-05-01 10:25:55 +08:00
parent da1641c46a
commit 3b75fdd56e
1 changed files with 12 additions and 1 deletions

View File

@ -128,13 +128,23 @@ func (n *Node) writePIDFile() {
}
n.PIDFile = path.Join(dir, filename)
err = ioutil.WriteFile(n.PIDFile, []byte(n.PID), 0600)
err = ioutil.WriteFile(n.PIDFile, []byte(n.PID), 0644)
if err != nil {
log.Errorf("Failed to write pid file: %s", err)
return
}
}
func (n *Node) removePIDFile() {
if len(n.PIDFile) == 0 {
return
}
if err := os.Remove(n.PIDFile); err != nil {
log.Warnf("Failed to remove pid file: %s", err)
}
}
// 断网掉线重新注册
func (n *Node) keepAlive() {
duration := time.Duration(n.ttl) * time.Second
@ -520,6 +530,7 @@ func (n *Node) Run() (err error) {
// 停止服务
func (n *Node) Stop(i interface{}) {
n.removePIDFile()
n.Node.Down()
close(n.done)
n.Node.Del()