[ Agent ] [ Executor ] - fix bugs

This commit is contained in:
zeaslity
2023-10-24 14:04:52 +08:00
parent 1224dd8def
commit ebb0759737
4 changed files with 19 additions and 10 deletions

View File

@@ -12,7 +12,7 @@ import (
type ExecutionMessage struct {
NeedResultReplay bool `json:"needResultReplay"`
DurationTask bool `json:"durationTask,default:false"`
Type string `json:"type"`
ExecutionType string `json:"executionType"`
FuncContent []string `json:"funcContent"`
SingleLineCommand []string `json:"singleLineCommand"`
MultiLineCommand [][]string `json:"multiLineCommand"`
@@ -31,7 +31,9 @@ func Execute(em *ExecutionMessage) ([]string, error) {
var realCommand [][]string
ok := true
if strings.HasPrefix(em.Type, "BASE") {
log.DebugF("em message is => %#v", em)
if strings.HasPrefix(em.ExecutionType, "BASE") {
// base function
if len(em.FuncContent) > 1 {
ok, resultLog = AgentOsOperatorCache.Exec(em.FuncContent[0], em.FuncContent[1:]...)
@@ -42,7 +44,7 @@ func Execute(em *ExecutionMessage) ([]string, error) {
return resultLog, nil
}
} else if strings.HasPrefix(em.Type, "APP") {
} else if strings.HasPrefix(em.ExecutionType, "APP") {
// app function
if len(em.FuncContent) > 1 {
ok, resultLog = AgentOsOperatorCache.Deploy(em.FuncContent[0], em.FuncContent[1:]...)
@@ -57,7 +59,6 @@ func Execute(em *ExecutionMessage) ([]string, error) {
} else {
// shell command
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
// 管道命令
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)

View File

@@ -70,8 +70,13 @@ func FormatAllCommandExecutor(singleLineCommand []string) ([]string, error) {
// result
var resultSlice []string
var resultError error
var cmd *exec.Cmd
cmd := exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
if len(singleLineCommand) > 1 {
cmd = exec.Command(singleLineCommand[0], singleLineCommand[1:]...)
} else {
cmd = exec.Command(singleLineCommand[0])
}
stdout, err := cmd.StdoutPipe()
if err != nil {
log.ErrorF("command %v stdout error => %v", singleLineCommand, err)

View File

@@ -277,9 +277,12 @@ CheckAndDownloadLatestVersion() {
echo ""
colorEcho $BLUE "start to download the agent config!"
agentConfigFileList=$(curl "$AgentConfigUrl/" | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4-)
rm -rf index.html
agentConfigFileList=$(curl "$AgentConfigUrl/" | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4- | tr "\n" " ")
for agentConfig in "${agentConfigFileList[@]}"; do
IFS=" " read -ra file_array <<<"$agentConfigFileList"
for agentConfig in "${file_array[@]}"; do
colorEcho $BLUE "agent config file is => $agentConfig"
wget -q "$AgentConfigUrl/$agentConfig"
echo ""

View File

@@ -61,7 +61,7 @@ func main() {
// 打印文件信息
fmt.Printf("File Name: %s\n", file.Filename)
fmt.Printf("File Size: %d bytes\n", file.Size)
fmt.Printf("MIME Type: %s\n", file.Header.Get("Content-Type"))
fmt.Printf("MIME ExecutionType: %s\n", file.Header.Get("Content-ExecutionType"))
// 保存文件到本地
err = c.SaveUploadedFile(file, "./"+file.Filename)
@@ -87,7 +87,7 @@ func main() {
// 打印文件信息
fmt.Printf("File Name: %s\n", file.Filename)
fmt.Printf("File Size: %d bytes\n", file.Size)
fmt.Printf("MIME Type: %s\n", file.Header.Get("Content-Type"))
fmt.Printf("MIME ExecutionType: %s\n", file.Header.Get("Content-ExecutionType"))
// 保存文件到本地
err = c.SaveUploadedFile(file, "./"+file.Filename)
@@ -112,7 +112,7 @@ func main() {
// 设置响应头,使浏览器可以下载文件
c.Header("Content-Disposition", "attachment; filename="+fileName)
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-ExecutionType", "application/octet-stream")
c.Header("Content-Transfer-Encoding", "binary")
c.Header("Cache-Control", "no-cache")