[ Agent ] [ Executor ] - 优化基础脚本内容
This commit is contained in:
@@ -52,6 +52,7 @@ func BasicReplace(filename string, origin string, replace string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BasicFileExists 检测文件是否存在
|
||||||
func BasicFileExists(filename string) bool {
|
func BasicFileExists(filename string) bool {
|
||||||
|
|
||||||
cmd := exec.Command("test", "-f", filename)
|
cmd := exec.Command("test", "-f", filename)
|
||||||
@@ -77,6 +78,7 @@ func BasicFileExistAndNotNull(filename string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BasicPrettyPrint 打印执行结果
|
||||||
func BasicPrettyPrint(resultOk bool, resultLog []string) {
|
func BasicPrettyPrint(resultOk bool, resultLog []string) {
|
||||||
fmt.Printf("resultOK is => %#v\n", resultOk)
|
fmt.Printf("resultOK is => %#v\n", resultOk)
|
||||||
if resultLog == nil || len(resultLog) == 0 {
|
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) {
|
func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
|
||||||
|
|
||||||
if !strings.HasSuffix(serviceName, ".service") {
|
if !strings.HasSuffix(serviceName, ".service") {
|
||||||
@@ -104,7 +107,8 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
|
|||||||
for _, s := range systemdFilePath {
|
for _, s := range systemdFilePath {
|
||||||
resultOk, _ := PipelineCommandExecutor(
|
resultOk, _ := PipelineCommandExecutor(
|
||||||
[][]string{
|
[][]string{
|
||||||
{"ls",
|
{
|
||||||
|
"ls",
|
||||||
s,
|
s,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -146,6 +150,7 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
|
|||||||
return resultOK, resultLog
|
return resultOK, resultLog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BasicSystemdUp 使用Systemd启动服务,会判定服务器是否存在
|
||||||
func BasicSystemdUp(serviceName string) (ok bool, resultLog []string) {
|
func BasicSystemdUp(serviceName string) (ok bool, resultLog []string) {
|
||||||
|
|
||||||
if !strings.HasSuffix(serviceName, ".service") {
|
if !strings.HasSuffix(serviceName, ".service") {
|
||||||
@@ -205,6 +210,7 @@ func BasicSystemdUp(serviceName string) (ok bool, resultLog []string) {
|
|||||||
return resultOK, resultLog
|
return resultOK, resultLog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BasicTransPipelineCommand 转换手写的管道命令为可执行的形式
|
||||||
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
|
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
|
||||||
|
|
||||||
var pipelineCommandC [][]string
|
var pipelineCommandC [][]string
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import "strings"
|
|||||||
|
|
||||||
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
|
func BuildAgentOsOperator(osInfo string, ossOfflinePrefix string) *AgentOsOperator {
|
||||||
|
|
||||||
|
// todo build from env
|
||||||
AgentOsOperatorCache = &AgentOsOperator{
|
AgentOsOperatorCache = &AgentOsOperator{
|
||||||
InstallCommandPrefix: []string{
|
InstallCommandPrefix: []string{
|
||||||
"apt-get", "install", "-y",
|
"apt-get", "install", "--allow-downgrades", "-y",
|
||||||
},
|
},
|
||||||
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
|
RemoveCommandPrefix: []string{"apt", "remove", "-y"},
|
||||||
CanAccessInternet: true,
|
CanAccessInternet: true,
|
||||||
IsOsTypeUbuntu: true,
|
IsOsTypeUbuntu: true,
|
||||||
IsAgentInnerWall: true,
|
IsAgentInnerWall: false,
|
||||||
AgentArch: "amd64",
|
AgentArch: "amd64",
|
||||||
AgentOSReleaseCode: "focal",
|
AgentOSReleaseCode: "focal",
|
||||||
AgentServerInfo: nil,
|
AgentServerInfo: nil,
|
||||||
@@ -66,16 +67,41 @@ func detectByOsType(os *AgentOsOperator, osInfo string) {
|
|||||||
os.IsOsTypeUbuntu = true
|
os.IsOsTypeUbuntu = true
|
||||||
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
|
os.RemoveCommandPrefix = []string{"apt", "remove", "-y"}
|
||||||
os.InstallCommandPrefix = []string{
|
os.InstallCommandPrefix = []string{
|
||||||
"apt-get", "install", "-y",
|
"apt-get", "install", "--allow-downgrades", "-y",
|
||||||
}
|
}
|
||||||
|
|
||||||
// os release code
|
// os release code
|
||||||
osRealseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
|
osReleaseResult, _ := PipeLineCommandExecutor(ubuntuSsRealseCode)
|
||||||
os.AgentOSReleaseCode = osRealseResult[0]
|
os.AgentOSReleaseCode = osReleaseResult[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func detectByInternet(os *AgentOsOperator) {
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ octopus:
|
|||||||
executor:
|
executor:
|
||||||
# agent执行一条Command的最长超时时间
|
# agent执行一条Command的最长超时时间
|
||||||
processMaxTimeOut: 60
|
processMaxTimeOut: 60
|
||||||
ossOfflinePrefix: https://b2.107421.xyz
|
ossOfflinePrefix: "https://oss-s1.107421.xyz"
|
||||||
status:
|
status:
|
||||||
app:
|
app:
|
||||||
- Nginx/nginx
|
- Nginx/nginx
|
||||||
@@ -66,27 +66,4 @@ spring:
|
|||||||
enabled: true
|
enabled: true
|
||||||
# retry interval unit ms
|
# retry interval unit ms
|
||||||
max-interval: 65000
|
max-interval: 65000
|
||||||
initial-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
|
|
||||||
@@ -96,11 +96,6 @@ public class BaseFuncScheduler {
|
|||||||
BaseFunctionEnum.INSTALL_ZSH
|
BaseFunctionEnum.INSTALL_ZSH
|
||||||
);
|
);
|
||||||
|
|
||||||
/*funcService.callBaseFuncAndJudge(
|
|
||||||
masterTopicName,
|
|
||||||
BaseFunctionEnum.MODIFY_HOSTNAME,
|
|
||||||
List.of("master-node")
|
|
||||||
);*/
|
|
||||||
|
|
||||||
for (BaseFunctionEnum procedure : masterNodeProcedureList) {
|
for (BaseFunctionEnum procedure : masterNodeProcedureList) {
|
||||||
if (funcService.callBaseFuncAndJudge(
|
if (funcService.callBaseFuncAndJudge(
|
||||||
|
|||||||
Reference in New Issue
Block a user