重启edge-admin时确保同目录下的edge-api也能重启

This commit is contained in:
GoEdgeLab
2023-03-11 22:02:29 +08:00
parent 83e7a5dc14
commit e2c93b5a40
2 changed files with 13 additions and 1 deletions

View File

@@ -209,7 +209,7 @@ func (this *AppCmd) runStop() {
fmt.Println(this.product+" stopped ok, pid:", types.String(pid)) fmt.Println(this.product+" stopped ok, pid:", types.String(pid))
} }
// 重启 // RunRestart 重启
func (this *AppCmd) RunRestart() { func (this *AppCmd) RunRestart() {
this.runStop() this.runStop()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View File

@@ -20,6 +20,8 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"path/filepath"
"strings"
"syscall" "syscall"
"time" "time"
) )
@@ -364,6 +366,16 @@ func (this *AdminNode) listenSock() error {
} }
} }
// 停止当前目录下的API节点
var apiSock = gosock.NewTmpSock("edge-api")
apiReply, err := apiSock.Send(&gosock.Command{Code: "info"})
if err == nil {
adminExe, _ := os.Executable()
if len(adminExe) > 0 && apiReply != nil && strings.HasPrefix(maps.NewMap(apiReply.Params).GetString("path"), filepath.Dir(filepath.Dir(adminExe))) {
_, _ = apiSock.Send(&gosock.Command{Code: "stop"})
}
}
// 退出主进程 // 退出主进程
events.Notify(events.EventQuit) events.Notify(events.EventQuit)
os.Exit(0) os.Exit(0)