修复缓存策略页面空白的问题/stop命令改成QUIT信号

This commit is contained in:
GoEdgeLab
2020-10-14 18:44:11 +08:00
parent 8c206d997e
commit c31ef4f558
5 changed files with 43 additions and 11 deletions

3
cmd/edge-admin/build.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o edge-admin main.go

BIN
cmd/edge-admin/edge-admin Executable file

Binary file not shown.

View File

@@ -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")

View File

@@ -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
}

View File

@@ -8,8 +8,8 @@
<a href="" class="item" @click.prevent="createPolicy()">[创建]</a>
</second-menu>
<p class="comment" v-if="cachePolicies.length == 0">暂时还没有缓存策略。</p>
<table class="ui table selectable" v-if="cachePolicies.length > 0">
<p class="comment" v-if="cachePolicies == null || cachePolicies.length == 0">暂时还没有缓存策略。</p>
<table class="ui table selectable" v-if="cachePolicies != null && cachePolicies.length > 0">
<thead>
<tr>
<th>策略名称</th>