支持优雅退出

This commit is contained in:
刘祥超
2020-10-28 11:19:06 +08:00
parent 0be8b78201
commit 1d6b0559e6
19 changed files with 238 additions and 15 deletions

View File

@@ -2,6 +2,8 @@ package apps
import (
"fmt"
"github.com/TeaOSLab/EdgeNode/internal/events"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/types"
"io/ioutil"
"os"
@@ -50,11 +52,15 @@ func CheckPid(path string) *os.Process {
}
// 写入Pid
func WritePid(path string) error {
func WritePid() error {
path := Tea.Root + "/bin/pid"
fp, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY|os.O_RDONLY, 0666)
if err != nil {
return err
}
events.On(events.EventQuit, func() {
_ = fp.Close()
})
if runtime.GOOS != "windows" {
err = LockFile(fp)