mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-07 02:20:24 +08:00
在升级API节点前检查版本号
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package services
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
|
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -435,12 +437,19 @@ func (this *APINodeService) UploadAPINodeFile(ctx context.Context, req *pb.Uploa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查文件是否可执行
|
// 检查文件是否可执行
|
||||||
var testCmd = exec.Command(targetFile, "-V")
|
var versionCmd = exec.Command(targetFile, "-V")
|
||||||
err = testCmd.Run()
|
var versionBuf = &bytes.Buffer{}
|
||||||
|
versionCmd.Stdout = versionBuf
|
||||||
|
err = versionCmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("test file failed: " + err.Error())
|
return nil, errors.New("test file failed: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查版本
|
||||||
|
if stringutil.VersionCompare(versionCmd.String(), teaconst.Version) >= 0 {
|
||||||
|
return &pb.UploadAPINodeFileResponse{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 替换文件
|
// 替换文件
|
||||||
err = os.Remove(exe)
|
err = os.Remove(exe)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user