[Agent] [Executor] 重写BaseFunction
This commit is contained in:
@@ -276,10 +276,35 @@ func (op *AgentOsOperator) disableSwap() [][]string {
|
||||
|
||||
func (op *AgentOsOperator) disableSwapExec() (bool, []string) {
|
||||
|
||||
resultOK := true
|
||||
var resultLog []string
|
||||
|
||||
return resultOK, resultLog
|
||||
// 备份文件存在,pass
|
||||
if !BasicFileExists("/etc/fstab_back_wdd") {
|
||||
AllCommandExecutor([]string{
|
||||
"cp",
|
||||
"-f",
|
||||
"/etc/fstab",
|
||||
"/etc/fstab_back_wdd",
|
||||
})
|
||||
}
|
||||
// 执行关闭操作
|
||||
_, lre := AllCompleteExecutor(
|
||||
[][]string{
|
||||
{
|
||||
"swapoff",
|
||||
"-a",
|
||||
},
|
||||
{
|
||||
"sed",
|
||||
"-i",
|
||||
"/swap/d",
|
||||
"/etc/fstab",
|
||||
},
|
||||
})
|
||||
|
||||
resultLog = append(resultLog, lre...)
|
||||
|
||||
return true, resultLog
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) removeDocker() [][]string {
|
||||
@@ -311,7 +336,55 @@ func (op *AgentOsOperator) removeDocker() [][]string {
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) removeDockerExec() (bool, []string) {
|
||||
return false, nil
|
||||
var resultLog []string
|
||||
|
||||
dockerServiceStopCommand := [][]string{
|
||||
{
|
||||
"systemctl",
|
||||
"stop",
|
||||
"docker",
|
||||
},
|
||||
{
|
||||
"systemctl",
|
||||
"disable",
|
||||
"docker",
|
||||
},
|
||||
}
|
||||
|
||||
ok, l := AllCompleteExecutor(dockerServiceStopCommand)
|
||||
if !ok {
|
||||
resultLog = append(resultLog, l...)
|
||||
}
|
||||
|
||||
dockerStaff := []string{
|
||||
"docker-ce",
|
||||
"docker.io",
|
||||
"docker-ce-cli",
|
||||
"docker",
|
||||
"docker-common",
|
||||
"docker-latest",
|
||||
"docker-latest-logrotate",
|
||||
"docker-logrotate",
|
||||
"docker-selinux",
|
||||
"docker-engine-selinux",
|
||||
"docker-engine",
|
||||
"kubelet",
|
||||
"kubeadm",
|
||||
"kubectl",
|
||||
"docker-client",
|
||||
"docker-client-latest",
|
||||
}
|
||||
|
||||
for _, staff := range dockerStaff {
|
||||
removeCommand := append(op.RemoveCommandPrefix, staff)
|
||||
|
||||
ok, result := AllCommandExecutor(removeCommand)
|
||||
if !ok {
|
||||
resultLog = append(resultLog, result...)
|
||||
}
|
||||
}
|
||||
|
||||
return true, resultLog
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installDocker(args []string) [][]string {
|
||||
@@ -428,7 +501,92 @@ func (op *AgentOsOperator) installDocker(args []string) [][]string {
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
|
||||
return false, nil
|
||||
var resultLog []string
|
||||
resultOk = true
|
||||
|
||||
if op.IsOsTypeUbuntu {
|
||||
|
||||
installDependencyCommand := append(op.InstallCommandPrefix, []string{
|
||||
"apt-transport-https",
|
||||
"ca-certificates",
|
||||
"curl",
|
||||
"gnupg-agent",
|
||||
"software-properties-common",
|
||||
}...)
|
||||
|
||||
ok, l := AllCommandExecutor(installDependencyCommand)
|
||||
if !ok {
|
||||
//
|
||||
return false, l
|
||||
}
|
||||
|
||||
// add dependency
|
||||
if op.IsAgentInnerWall {
|
||||
// inner gfw
|
||||
installDockerFunc = append(installDockerFunc, [][]string{
|
||||
installFirstLine,
|
||||
{
|
||||
"curl",
|
||||
"-o",
|
||||
"/usr/share/keyrings/docker-utsc.gpg",
|
||||
"https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg",
|
||||
},
|
||||
{
|
||||
"apt-key",
|
||||
"add",
|
||||
"/usr/share/keyrings/docker-utsc.gpg",
|
||||
},
|
||||
{
|
||||
"add-apt-repository",
|
||||
"deb [arch=" + op.AgentArch + "] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu " + op.AgentOSReleaseCode + " stable",
|
||||
},
|
||||
}...)
|
||||
} else {
|
||||
// outside world
|
||||
installDockerFunc = append(installDockerFunc, [][]string{
|
||||
installFirstLine,
|
||||
{
|
||||
"curl",
|
||||
"-o",
|
||||
"/usr/share/keyrings/docker.gpg",
|
||||
"https://download.docker.com/linux/ubuntu/gpg ",
|
||||
},
|
||||
{
|
||||
"apt-key",
|
||||
"add",
|
||||
"/usr/share/keyrings/docker.gpg",
|
||||
},
|
||||
{
|
||||
"add-apt-repository",
|
||||
"deb [arch=" + op.AgentArch + "] https://download.docker.com/linux/ubuntu " + op.AgentOSReleaseCode + " stable",
|
||||
},
|
||||
}...)
|
||||
}
|
||||
|
||||
// look for specific docker-version to install
|
||||
installDockerFunc = append(installDockerFunc, []string{"apt-get", "update"})
|
||||
|
||||
var specificDockerVersion string
|
||||
// hard code here 5:20.10.10~3-0~ubuntu-focal
|
||||
if strings.HasPrefix(args[0], "19") {
|
||||
specificDockerVersion = "5:19.03.15~3-0~ubuntu-" + op.AgentOSReleaseCode
|
||||
} else {
|
||||
specificDockerVersion = "5:20.10.10~3-0~ubuntu-" + op.AgentOSReleaseCode
|
||||
}
|
||||
|
||||
installDockerFunc = append(installDockerFunc,
|
||||
append(
|
||||
op.InstallCommandPrefix,
|
||||
"docker-ce="+specificDockerVersion,
|
||||
"docker-ce-cli="+specificDockerVersion,
|
||||
"containerd.io",
|
||||
"docker-compose-plugin",
|
||||
),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
return resultOk, resultLog
|
||||
}
|
||||
|
||||
func (op *AgentOsOperator) removeDockerCompose() [][]string {
|
||||
|
||||
Reference in New Issue
Block a user