[ Agent ] [ Executor ] - fix bugs
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
type ExecutionMessage struct {
|
type ExecutionMessage struct {
|
||||||
NeedResultReplay bool `json:"needResultReplay"`
|
NeedResultReplay bool `json:"needResultReplay"`
|
||||||
DurationTask bool `json:"durationTask,default:false"`
|
DurationTask bool `json:"durationTask,default:false"`
|
||||||
Type string `json:"type"`
|
ExecutionType string `json:"executionType"`
|
||||||
FuncContent []string `json:"funcContent"`
|
FuncContent []string `json:"funcContent"`
|
||||||
SingleLineCommand []string `json:"singleLineCommand"`
|
SingleLineCommand []string `json:"singleLineCommand"`
|
||||||
MultiLineCommand [][]string `json:"multiLineCommand"`
|
MultiLineCommand [][]string `json:"multiLineCommand"`
|
||||||
@@ -31,7 +31,9 @@ func Execute(em *ExecutionMessage) ([]string, error) {
|
|||||||
var realCommand [][]string
|
var realCommand [][]string
|
||||||
ok := true
|
ok := true
|
||||||
|
|
||||||
if strings.HasPrefix(em.Type, "BASE") {
|
log.DebugF("em message is => %#v", em)
|
||||||
|
|
||||||
|
if strings.HasPrefix(em.ExecutionType, "BASE") {
|
||||||
// base function
|
// base function
|
||||||
if len(em.FuncContent) > 1 {
|
if len(em.FuncContent) > 1 {
|
||||||
ok, resultLog = AgentOsOperatorCache.Exec(em.FuncContent[0], 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
|
return resultLog, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if strings.HasPrefix(em.Type, "APP") {
|
} else if strings.HasPrefix(em.ExecutionType, "APP") {
|
||||||
// app function
|
// app function
|
||||||
if len(em.FuncContent) > 1 {
|
if len(em.FuncContent) > 1 {
|
||||||
ok, resultLog = AgentOsOperatorCache.Deploy(em.FuncContent[0], em.FuncContent[1:]...)
|
ok, resultLog = AgentOsOperatorCache.Deploy(em.FuncContent[0], em.FuncContent[1:]...)
|
||||||
@@ -57,7 +59,6 @@ func Execute(em *ExecutionMessage) ([]string, error) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// shell command
|
// shell command
|
||||||
|
|
||||||
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
|
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
|
||||||
// 管道命令
|
// 管道命令
|
||||||
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
|
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
|
||||||
|
|||||||
@@ -70,8 +70,13 @@ func FormatAllCommandExecutor(singleLineCommand []string) ([]string, error) {
|
|||||||
// result
|
// result
|
||||||
var resultSlice []string
|
var resultSlice []string
|
||||||
var resultError error
|
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()
|
stdout, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorF("command %v stdout error => %v", singleLineCommand, err)
|
log.ErrorF("command %v stdout error => %v", singleLineCommand, err)
|
||||||
|
|||||||
@@ -277,9 +277,12 @@ CheckAndDownloadLatestVersion() {
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
colorEcho $BLUE "start to download the agent config!"
|
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"
|
colorEcho $BLUE "agent config file is => $agentConfig"
|
||||||
wget -q "$AgentConfigUrl/$agentConfig"
|
wget -q "$AgentConfigUrl/$agentConfig"
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func main() {
|
|||||||
// 打印文件信息
|
// 打印文件信息
|
||||||
fmt.Printf("File Name: %s\n", file.Filename)
|
fmt.Printf("File Name: %s\n", file.Filename)
|
||||||
fmt.Printf("File Size: %d bytes\n", file.Size)
|
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)
|
err = c.SaveUploadedFile(file, "./"+file.Filename)
|
||||||
@@ -87,7 +87,7 @@ func main() {
|
|||||||
// 打印文件信息
|
// 打印文件信息
|
||||||
fmt.Printf("File Name: %s\n", file.Filename)
|
fmt.Printf("File Name: %s\n", file.Filename)
|
||||||
fmt.Printf("File Size: %d bytes\n", file.Size)
|
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)
|
err = c.SaveUploadedFile(file, "./"+file.Filename)
|
||||||
@@ -112,7 +112,7 @@ func main() {
|
|||||||
|
|
||||||
// 设置响应头,使浏览器可以下载文件
|
// 设置响应头,使浏览器可以下载文件
|
||||||
c.Header("Content-Disposition", "attachment; filename="+fileName)
|
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("Content-Transfer-Encoding", "binary")
|
||||||
c.Header("Cache-Control", "no-cache")
|
c.Header("Cache-Control", "no-cache")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user