diff --git a/go.mod b/go.mod index 5b008ae4..d0545b81 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/go-yaml/yaml v2.1.0+incompatible github.com/google/go-cmp v0.5.6 // indirect github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24 - github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3 + github.com/iwind/gosock v0.0.0-20211103081026-ee4652210ca4 github.com/json-iterator/go v1.1.12 // indirect github.com/miekg/dns v1.1.35 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/go.sum b/go.sum index 0463e006..f9fa0206 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24 h1:1cGulkD2SNJJRok5OKw github.com/iwind/TeaGo v0.0.0-20211026123858-7de7a21cad24/go.mod h1:KU4mS7QNiZ7QWEuDBk1zw0/Q2LrAPZv3tycEFBsuUwc= github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3 h1:aBSonas7vFcgTj9u96/bWGILGv1ZbUSTLiOzcI1ZT6c= github.com/iwind/gosock v0.0.0-20210722083328-12b2d66abec3/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA= +github.com/iwind/gosock v0.0.0-20211103081026-ee4652210ca4 h1:VWGsCqTzObdlbf7UUE3oceIpcEKi4C/YBUszQXk118A= +github.com/iwind/gosock v0.0.0-20211103081026-ee4652210ca4/go.mod h1:H5Q7SXwbx3a97ecJkaS2sD77gspzE7HFUafBO0peEyA= github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= diff --git a/internal/web/actions/default/setup/install.go b/internal/web/actions/default/setup/install.go index 95468c77..d408defe 100644 --- a/internal/web/actions/default/setup/install.go +++ b/internal/web/actions/default/setup/install.go @@ -16,6 +16,7 @@ import ( "github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/logs" "github.com/iwind/TeaGo/maps" + "github.com/iwind/gosock/pkg/gosock" "io/ioutil" "os" "os/exec" @@ -167,6 +168,9 @@ func (this *InstallAction) RunPost(params struct { if !resultMap.GetBool("isOk") { this.Fail("节点安装错误:" + resultMap.GetString("error")) } + + // 等数据完全写入 + time.Sleep(1 * time.Second) } // 关闭正在运行的API节点,防止冲突 @@ -190,7 +194,30 @@ func (this *InstallAction) RunPost(params struct { nodes.SharedAdminNode.AddSubPID(cmd.Process.Pid) // 等待API节点初始化完成 - time.Sleep(5 * time.Second) + currentStatusText = "正在等待API节点启动完毕" + var apiNodeSock = gosock.NewTmpSock("edge-api") + var maxRetries = 5 + for { + reply, err := apiNodeSock.SendTimeout(&gosock.Command{ + Code: "starting", + }, 3*time.Second) + if err != nil { + if maxRetries < 0 { + this.Fail("API节点启动失败,请查看运行日志检查是否正常") + } else { + time.Sleep(3 * time.Second) + maxRetries-- + } + } else { + if !maps.NewMap(reply.Params).GetBool("isStarting") { + currentStatusText = "API节点启动完毕" + break + } + + // 继续等待完成 + time.Sleep(3 * time.Second) + } + } } // 写入API节点配置,完成安装 diff --git a/web/views/@default/setup/confirm/index.html b/web/views/@default/setup/confirm/index.html index 7e4c5a10..372a380a 100644 --- a/web/views/@default/setup/confirm/index.html +++ b/web/views/@default/setup/confirm/index.html @@ -47,6 +47,7 @@
+ 重新安装