diff --git a/cmd/edge-admin/build.sh b/cmd/edge-admin/build.sh new file mode 100755 index 00000000..41101fc6 --- /dev/null +++ b/cmd/edge-admin/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o edge-admin main.go \ No newline at end of file diff --git a/cmd/edge-admin/edge-admin b/cmd/edge-admin/edge-admin new file mode 100755 index 00000000..3706e2cb Binary files /dev/null and b/cmd/edge-admin/edge-admin differ diff --git a/internal/apps/app_cmd.go b/internal/apps/app_cmd.go index 7e671515..425aa4bb 100644 --- a/internal/apps/app_cmd.go +++ b/internal/apps/app_cmd.go @@ -8,6 +8,7 @@ import ( "os/exec" "runtime" "strconv" + "syscall" "time" ) @@ -199,7 +200,7 @@ func (this *AppCmd) runStop() { } // 停止进程 - _ = proc.Kill() + _ = proc.Signal(syscall.SIGQUIT) // 在Windows上经常不能及时释放资源 _ = DeletePid(Tea.Root + "/bin/pid") diff --git a/internal/nodes/admin_node.go b/internal/nodes/admin_node.go index 26167ce6..91189cc4 100644 --- a/internal/nodes/admin_node.go +++ b/internal/nodes/admin_node.go @@ -10,9 +10,12 @@ import ( "io/ioutil" "os" "os/exec" + "os/signal" + "syscall" ) type AdminNode struct { + subPIDs []int } func NewAdminNode() *AdminNode { @@ -21,12 +24,7 @@ func NewAdminNode() *AdminNode { func (this *AdminNode) Run() { // 启动管理界面 - secret := rands.String(32) - - // 测试环境下设置一个固定的key,方便我们调试 - if Tea.IsTesting() { - secret = "8f983f4d69b83aaa0d74b21a212f6967" - } + secret := this.genSecret() // 检查server配置 err := this.checkServer() @@ -34,6 +32,21 @@ func (this *AdminNode) Run() { return } + // 监听信号 + sigQueue := make(chan os.Signal) + signal.Notify(sigQueue, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT) + go func() { + for range sigQueue { + for _, pid := range this.subPIDs { + p, err := os.FindProcess(pid) + if err == nil && p != nil { + _ = p.Kill() + } + } + os.Exit(0) + } + }() + // 启动API节点 this.startAPINode() @@ -91,13 +104,28 @@ https: } // 启动API节点 -func (this AdminNode) startAPINode() { +func (this *AdminNode) startAPINode() { _, err := os.Stat(Tea.Root + "/edge-api/configs/api.yaml") if err == nil { logs.Println("start edge-api") - err = exec.Command(Tea.Root + "/edge-api/bin/edge-api").Start() + cmd := exec.Command(Tea.Root + "/edge-api/bin/edge-api") + err = cmd.Start() if err != nil { logs.Println("[ERROR]start edge-api failed: " + err.Error()) + } else { + this.subPIDs = append(this.subPIDs, cmd.Process.Pid) } } } + +// 生成Secret +func (this *AdminNode) genSecret() string { + tmpFile := os.TempDir() + "/edge-secret.tmp" + data, err := ioutil.ReadFile(tmpFile) + if err == nil && len(data) == 32 { + return string(data) + } + secret := rands.String(32) + _ = ioutil.WriteFile(tmpFile, []byte(secret), 0666) + return secret +} diff --git a/web/views/@default/servers/components/cache/index.html b/web/views/@default/servers/components/cache/index.html index 951793d2..98dfeb7b 100644 --- a/web/views/@default/servers/components/cache/index.html +++ b/web/views/@default/servers/components/cache/index.html @@ -8,8 +8,8 @@ [创建] -
暂时还没有缓存策略。
-| 策略名称 | 
|---|