mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-15 21:20:25 +08:00
使用edge-admin upgrade时自动执行本地安装的edge-api upgrade
This commit is contained in:
@@ -9,8 +9,11 @@ import (
|
|||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/gen"
|
"github.com/TeaOSLab/EdgeAdmin/internal/gen"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
|
"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
|
executils "github.com/TeaOSLab/EdgeAdmin/internal/utils/exec"
|
||||||
_ "github.com/TeaOSLab/EdgeAdmin/internal/web"
|
_ "github.com/TeaOSLab/EdgeAdmin/internal/web"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/updates/updateutils"
|
||||||
_ "github.com/TeaOSLab/EdgeCommon/pkg/langs/messages"
|
_ "github.com/TeaOSLab/EdgeCommon/pkg/langs/messages"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "github.com/iwind/TeaGo/bootstrap"
|
||||||
@@ -176,6 +179,18 @@ func main() {
|
|||||||
log.Println("upgrade failed: " + err.Error())
|
log.Println("upgrade failed: " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// try to exec local 'edge-api upgrade'
|
||||||
|
rpcClient, err := rpc.SharedRPC()
|
||||||
|
if err == nil {
|
||||||
|
exePath, ok := updateutils.CheckLocalAPINode(rpcClient, rpcClient.Context(0))
|
||||||
|
if ok && len(exePath) > 0 {
|
||||||
|
log.Println("upgrading database ...")
|
||||||
|
var cmd = executils.NewCmd(exePath, "upgrade")
|
||||||
|
_ = cmd.Run()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("finished!")
|
log.Println("finished!")
|
||||||
log.Println("restarting ...")
|
log.Println("restarting ...")
|
||||||
app.RunRestart()
|
app.RunRestart()
|
||||||
|
|||||||
@@ -5,13 +5,11 @@ const (
|
|||||||
|
|
||||||
APINodeVersion = "1.3.8"
|
APINodeVersion = "1.3.8"
|
||||||
|
|
||||||
ProductName = "Edge Admin"
|
ProductName = "Edge Admin"
|
||||||
ProcessName = "edge-admin"
|
ProcessName = "edge-admin"
|
||||||
ProductNameZH = "Edge"
|
|
||||||
|
|
||||||
Role = "admin"
|
Role = "admin"
|
||||||
|
|
||||||
EncryptKey = "8f983f4d69b83aaa0d74b21a212f6967"
|
|
||||||
EncryptMethod = "aes-256-cfb"
|
EncryptMethod = "aes-256-cfb"
|
||||||
|
|
||||||
CookieSID = "geadsid"
|
CookieSID = "geadsid"
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package updateutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckLocalAPINode(rpcClient *rpc.RPCClient, ctx context.Context) (exePath string, ok bool) {
|
||||||
|
resp, err := rpcClient.APINodeRPC().FindCurrentAPINode(ctx, &pb.FindCurrentAPINodeRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if resp.ApiNode == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var instanceCode = resp.ApiNode.InstanceCode
|
||||||
|
if len(instanceCode) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var statusJSON = resp.ApiNode.StatusJSON
|
||||||
|
if len(statusJSON) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var status = &nodeconfigs.NodeStatus{}
|
||||||
|
err = json.Unmarshal(statusJSON, status)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
exePath = status.ExePath
|
||||||
|
if len(exePath) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stat, err := os.Stat(exePath)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if stat.IsDir() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 实例信息
|
||||||
|
{
|
||||||
|
var outputBuffer = &bytes.Buffer{}
|
||||||
|
var cmd = exec.Command(exePath, "instance")
|
||||||
|
cmd.Stdout = outputBuffer
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var outputBytes = outputBuffer.Bytes()
|
||||||
|
if len(outputBytes) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var instanceMap = maps.Map{}
|
||||||
|
err = json.Unmarshal(bytes.TrimSpace(outputBytes), &instanceMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if instanceMap.GetString("code") != instanceCode {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -3,15 +3,11 @@
|
|||||||
package updates
|
package updates
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
|
||||||
executils "github.com/TeaOSLab/EdgeAdmin/internal/utils/exec"
|
executils "github.com/TeaOSLab/EdgeAdmin/internal/utils/exec"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/updates/updateutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
||||||
"github.com/iwind/TeaGo/maps"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
@@ -69,7 +65,7 @@ func (this *UpgradeAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try to exec local 'edge-api upgrade'
|
// try to exec local 'edge-api upgrade'
|
||||||
exePath, ok := this.checkLocalAPINode()
|
exePath, ok := updateutils.CheckLocalAPINode(this.RPC(), this.AdminContext())
|
||||||
if ok && len(exePath) > 0 {
|
if ok && len(exePath) > 0 {
|
||||||
isUpgradingDB = true
|
isUpgradingDB = true
|
||||||
var before = time.Now()
|
var before = time.Now()
|
||||||
@@ -95,69 +91,3 @@ func (this *UpgradeAction) RunPost(params struct {
|
|||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *UpgradeAction) checkLocalAPINode() (exePath string, ok bool) {
|
|
||||||
resp, err := this.RPC().APINodeRPC().FindCurrentAPINode(this.AdminContext(), &pb.FindCurrentAPINodeRequest{})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if resp.ApiNode == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var instanceCode = resp.ApiNode.InstanceCode
|
|
||||||
if len(instanceCode) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var statusJSON = resp.ApiNode.StatusJSON
|
|
||||||
if len(statusJSON) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var status = &nodeconfigs.NodeStatus{}
|
|
||||||
err = json.Unmarshal(statusJSON, status)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
exePath = status.ExePath
|
|
||||||
if len(exePath) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
stat, err := os.Stat(exePath)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if stat.IsDir() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 实例信息
|
|
||||||
{
|
|
||||||
var outputBuffer = &bytes.Buffer{}
|
|
||||||
var cmd = exec.Command(exePath, "instance")
|
|
||||||
cmd.Stdout = outputBuffer
|
|
||||||
err = cmd.Run()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var outputBytes = outputBuffer.Bytes()
|
|
||||||
if len(outputBytes) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var instanceMap = maps.Map{}
|
|
||||||
err = json.Unmarshal(bytes.TrimSpace(outputBytes), &instanceMap)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if instanceMap.GetString("code") != instanceCode {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user