[ Agent ] [ Executor ] - 优化基础脚本内容

This commit is contained in:
zeaslity
2023-11-07 10:02:19 +08:00
parent ebb0759737
commit b17f1dcb52
4 changed files with 40 additions and 36 deletions

View File

@@ -52,6 +52,7 @@ func BasicReplace(filename string, origin string, replace string) bool {
}
}
// BasicFileExists 检测文件是否存在
func BasicFileExists(filename string) bool {
cmd := exec.Command("test", "-f", filename)
@@ -77,6 +78,7 @@ func BasicFileExistAndNotNull(filename string) bool {
}
}
// BasicPrettyPrint 打印执行结果
func BasicPrettyPrint(resultOk bool, resultLog []string) {
fmt.Printf("resultOK is => %#v\n", resultOk)
if resultLog == nil || len(resultLog) == 0 {
@@ -87,6 +89,7 @@ func BasicPrettyPrint(resultOk bool, resultLog []string) {
}
}
// BasicSystemdShutdown 使用Systemd关闭服务,会判定服务器是否存在
func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
if !strings.HasSuffix(serviceName, ".service") {
@@ -104,7 +107,8 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
for _, s := range systemdFilePath {
resultOk, _ := PipelineCommandExecutor(
[][]string{
{"ls",
{
"ls",
s,
},
{
@@ -146,6 +150,7 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
return resultOK, resultLog
}
// BasicSystemdUp 使用Systemd启动服务,会判定服务器是否存在
func BasicSystemdUp(serviceName string) (ok bool, resultLog []string) {
if !strings.HasSuffix(serviceName, ".service") {
@@ -205,6 +210,7 @@ func BasicSystemdUp(serviceName string) (ok bool, resultLog []string) {
return resultOK, resultLog
}
// BasicTransPipelineCommand 转换手写的管道命令为可执行的形式
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
var pipelineCommandC [][]string

View File

@@ -4,14 +4,15 @@ import "strings"
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
// todo build from env
AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{
"apt-get", "install", "-y",
"apt-get", "install", "--allow-downgrades", "-y",
},
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
CanAccessInternet: true,
IsOsTypeUbuntu: true,
IsAgentInnerWall: true,
IsAgentInnerWall: false,
AgentArch: "amd64",
AgentOSReleaseCode: "focal",
AgentServerInfo: nil,
@@ -66,16 +67,41 @@ func detectByOsType(os *AgentOsOperator, osInfo string) {
os.IsOsTypeUbuntu = true
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
os.InstallCommandPrefix = []string{
"apt-get", "install", "-y",
"apt-get", "install", "--allow-downgrades", "-y",
}
// os release code
osRealseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
os.AgentOSReleaseCode = osRealseResult[0]
osReleaseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
os.AgentOSReleaseCode = osReleaseResult[0]
}
}
func detectByInternet(os *AgentOsOperator) {
log.Info("开始检测Agent的网络连通情况!")
outsideTestUrl := "www.google.com"
innerTestUrl := "www.baidu.com"
testInternetCommand := []string{
"curl",
"-o",
"/dev/null",
"-m",
"5",
"-s",
}
if PureResultSingleExecute(append(testInternetCommand, outsideTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = false
} else if PureResultSingleExecute(append(testInternetCommand, innerTestUrl)) {
os.CanAccessInternet = true
os.IsAgentInnerWall = true
} else {
os.CanAccessInternet = false
os.IsAgentInnerWall = true
}
}

View File

@@ -37,7 +37,7 @@ octopus:
executor:
# agent执行一条Command的最长超时时间
processMaxTimeOut: 60
ossOfflinePrefix: https://b2.107421.xyz
ossOfflinePrefix: "https://oss-s1.107421.xyz"
status:
app:
- Nginx/nginx
@@ -66,27 +66,4 @@ spring:
enabled: true
# retry interval unit ms
max-interval: 65000
initial-interval: 65000
#spring:
# application:
# name: octopus-agent
# profiles:
# active: dev
# cloud:
# nacos:
# config:
# group: dev
# config-retry-time: 3000
# file-extension: yaml
# max-retry: 3
# # server-addr: "150.230.198.103:21060"
# server-addr: "42.192.52.227:21060"
# timeout: 5000
# config-long-poll-timeout: 5000
# extension-configs:
# - group: dev
# data-id: "common-dev.yaml"
#
#server:
# port: 8000
initial-interval: 65000