[ Agent ] [ Base ] - add support for centos/openeuler ; todo chronyToMasterExec centos

This commit is contained in:
zeaslity
2024-01-19 18:34:36 +08:00
parent 7b57a2a422
commit 42dee262cf
7 changed files with 290 additions and 128 deletions

View File

@@ -5,6 +5,7 @@ import (
"agent-go/g" "agent-go/g"
"agent-go/rabbitmq" "agent-go/rabbitmq"
"agent-go/register" "agent-go/register"
"agent-go/status"
"encoding/json" "encoding/json"
"fmt" "fmt"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@@ -24,6 +25,13 @@ func INIT(agentServerInfoConf string) chan bool {
// 获取系统的环境变量 // 获取系统的环境变量
agentServerInfo := parseAgentServerInfo(agentServerInfoConf) agentServerInfo := parseAgentServerInfo(agentServerInfoConf)
// re-get agentInfo from status module
agentInfo := status.ReportAgentInfo()
refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo)
// build operator cache
BuildAgentOsOperator(agentInfo, agentServerInfo)
// 缓存此内容 // 缓存此内容
//AgentServerInfoCache = agentServerInfo //AgentServerInfoCache = agentServerInfo
@@ -95,6 +103,17 @@ func INIT(agentServerInfoConf string) chan bool {
return businessForeverChan return businessForeverChan
} }
func refreshAgentInfoByStatusInfo(agentInfo *status.AgentInfo, agentServerInfo *register.AgentServerInfo) {
agentServerInfo.Platform = agentInfo.HostInfo.Platform
agentServerInfo.PlatformFamily = agentInfo.HostInfo.PlatformFamily
agentServerInfo.PlatformVersion = agentInfo.HostInfo.PlatformVersion
agentServerInfo.KernelVersion = agentInfo.HostInfo.KernelVersion
agentServerInfo.KernelArch = agentInfo.HostInfo.KernelArch
log.DebugF("[refreshAgentInfoByStatusInfo] - ok !")
}
// handleInitMsgFromServer 处理从Server接收的 注册信息 // handleInitMsgFromServer 处理从Server接收的 注册信息
func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue, agentServerInfo *register.AgentServerInfo) chan bool { func handleInitMsgFromServer(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue, agentServerInfo *register.AgentServerInfo) chan bool {
@@ -187,9 +206,6 @@ func parseAgentServerInfo(agentServerInfoConf string) *register.AgentServerInfo
// uniform agent server info // uniform agent server info
UniformAgentServerInfo(agentServerInfo) UniformAgentServerInfo(agentServerInfo)
// build operator cache
BuildAgentOsOperator(agentServerInfo)
jsonFormat, err := json.Marshal(&agentServerInfo) jsonFormat, err := json.Marshal(&agentServerInfo)
if err != nil { if err != nil {
log.Error(fmt.Sprintf("agent server info convert error ! agentserverinfo is %v", agentServerInfo)) log.Error(fmt.Sprintf("agent server info convert error ! agentserverinfo is %v", agentServerInfo))
@@ -225,7 +241,7 @@ func UniformAgentServerInfo(agentServerInfo *register.AgentServerInfo) {
} }
func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) { func BuildAgentOsOperator(agentInfo *status.AgentInfo, agentServerInfo *register.AgentServerInfo) {
// 2023年8月4日 pass through some key information // 2023年8月4日 pass through some key information
ossOfflinePrefix := g.G.AgentConfig.GetString("octopus.agent.executor.ossOfflinePrefix") ossOfflinePrefix := g.G.AgentConfig.GetString("octopus.agent.executor.ossOfflinePrefix")
@@ -234,7 +250,7 @@ func BuildAgentOsOperator(agentServerInfo *register.AgentServerInfo) {
} }
// call the init exec function // call the init exec function
agentOsOperator := executor.BuildAgentOsOperator(ossOfflinePrefix) agentOsOperator := executor.BuildAgentOsOperator(agentInfo, ossOfflinePrefix)
// assign the agentServerInfo // assign the agentServerInfo
agentOsOperator.AgentServerInfo = agentServerInfo agentOsOperator.AgentServerInfo = agentServerInfo

View File

@@ -58,6 +58,9 @@ func (op *AgentOsOperator) Exec(baseFuncName string, funcArgs ...string) (bool,
case "disableSwap": case "disableSwap":
resultOk, errorLog = op.disableSwapExec() resultOk, errorLog = op.disableSwapExec()
break break
case "DISABLE_SELINUX":
resultOk, errorLog = op.disableSELinuxExec()
break
case "installDocker": case "installDocker":
resultOk, errorLog = op.installDockerExec(funcArgs) resultOk, errorLog = op.installDockerExec(funcArgs)
break break
@@ -322,6 +325,30 @@ func (op *AgentOsOperator) disableSwapExec() (bool, []string) {
return true, resultLog return true, resultLog
} }
func (op *AgentOsOperator) disableSELinuxExec() (bool, []string) {
if op.IsOsTypeUbuntu {
return true, []string{
"[disableSELinuxExec] - os is ubuntu, success",
}
}
// delete contend
BasicFindDeleteContendLineInFile("SELINUX=enforcing", "/etc/selinux/config")
BasicFindDeleteContendLineInFile("SELINUX=permissive", "/etc/selinux/config")
BasicFindDeleteContendLineInFile("SELINUX=disabled", "/etc/selinux/config")
BasicAppendContentToFile("SELINUX=disabled", "/etc/selinux/config")
// shutdown
AllCommandExecutor([]string{
"setenforce",
"0",
})
return true, []string{}
}
func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []string) { func (op *AgentOsOperator) installDefaultSSHKeyExec(funcArgs []string) (bool, []string) {
// ssh-keygen -t ed25519 -C "wdd@cmii.com" // ssh-keygen -t ed25519 -C "wdd@cmii.com"
@@ -569,7 +596,7 @@ func (op *AgentOsOperator) installDocker(args []string) [][]string {
func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) { func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
BasicCreateFolder("/root/install/") BasicCreateFolder("/root/wdd/")
if op.IsOsTypeUbuntu { if op.IsOsTypeUbuntu {
@@ -749,6 +776,12 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
if !completeExecutor { if !completeExecutor {
return false, append(log5, "启动docker.service失败请查明原因", "journalctl -u docker -n 100 -f") return false, append(log5, "启动docker.service失败请查明原因", "journalctl -u docker -n 100 -f")
} }
} else if op.IsOsTypeCentOS {
if !op.CanAccessInternet {
// offline version
log.InfoF("[installDockerExec] - centos can not access to internet, installing by offline !")
return op.installDockerOfflineExec(args)
}
} }
return true, []string{ return true, []string{
@@ -759,34 +792,34 @@ func (op *AgentOsOperator) installDockerExec(args []string) (bool, []string) {
func (op *AgentOsOperator) installDockerOfflineExec(args []string) (bool, []string) { func (op *AgentOsOperator) installDockerOfflineExec(args []string) (bool, []string) {
log.InfoF("[installDockerOfflineExec] - install docker 20.10.15 by offline method !") log.InfoF("[installDockerOfflineExec] - install docker 20.10.15 by offline method !")
BasicCreateFolder("/root/install") BasicCreateFolder("/root/wdd")
// download static binary installer of docker // download static binary installer of docker
var dockerOfflineFileName string var dockerOfflineFileName string
if strings.HasPrefix(op.AgentArch, "amd") { if strings.HasPrefix(op.AgentArch, "amd") {
dockerOfflineFileName = "docker-amd64-20.10.15.tgz" dockerOfflineFileName = "docker-amd64-20.10.15.tgz"
} else if strings.HasPrefix(op.AgentArch, "arm") { } else if strings.HasPrefix(op.AgentArch, "arm64") {
dockerOfflineFileName = "docker-arm64-20.10.15.tgz" dockerOfflineFileName = "docker-arm64-20.10.15.tgz"
} }
ok, resultLog := BasicDownloadFile(op.OssOfflinePrefix+dockerOfflineFileName, "/root/install/"+dockerOfflineFileName) ok, resultLog := BasicDownloadFile(op.OssOfflinePrefix+dockerOfflineFileName, "/root/wdd/"+dockerOfflineFileName)
if !ok { if !ok {
return false, resultLog return false, resultLog
} }
BasicRemoveFolderComplete("/root/install/docker") BasicRemoveFolderComplete("/root/wdd/docker")
PureResultSingleExecute([]string{ PureResultSingleExecute([]string{
"tar", "tar",
"-vxf", "-vxf",
"/root/install/" + dockerOfflineFileName, "/root/wdd/" + dockerOfflineFileName,
"-C", "-C",
"/root/install", "/root/wdd",
}) })
HardCodeCommandExecutor("chmod 777 -R /root/install/docker/*") HardCodeCommandExecutor("chmod 777 -R /root/wdd/docker/*")
resultOk, l := HardCodeCommandExecutor("mv /root/install/docker/* /usr/bin") resultOk, l := HardCodeCommandExecutor("mv /root/wdd/docker/* /usr/bin")
if !resultOk { if !resultOk {
return false, append(l, "[installDockerOfflineExec] - cp docker executable file error!") return false, append(l, "[installDockerOfflineExec] - cp docker executable file error!")
} }
@@ -922,7 +955,7 @@ func (op *AgentOsOperator) installDockerComposeExec() (bool, []string) {
var DockerComposeFile string var DockerComposeFile string
if strings.HasPrefix(op.AgentArch, "amd") { if strings.HasPrefix(op.AgentArch, "amd") {
DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-x86_64-v2.18.0" DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-x86_64-v2.18.0"
} else if strings.HasPrefix(op.AgentArch, "arm") { } else if strings.HasPrefix(op.AgentArch, "arm64") {
DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-aarch64-v2.18.0" DockerComposeFile = op.OssOfflinePrefix + "docker-compose-linux-aarch64-v2.18.0"
} }
@@ -1109,11 +1142,11 @@ func (op *AgentOsOperator) modifyDockerConfigExec(args []string) (bool, []string
} }
func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) { func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
if op.IsOsTypeUbuntu { if !op.CanAccessInternet {
return op.installNFSOfflineExec()
}
if !op.CanAccessInternet { if op.IsOsTypeUbuntu {
return op.installNFSOfflineExec()
}
// ubuntu // ubuntu
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, false, installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, false,
@@ -1126,6 +1159,20 @@ func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
if !ok { if !ok {
return false, append(resultLog, "[installNfsOnlineExec] - start nfs-common.service failed !") return false, append(resultLog, "[installNfsOnlineExec] - start nfs-common.service failed !")
} }
} else if op.IsOsTypeCentOS {
// centos
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, false,
"nfs-utils")
if !installOk {
return false, installLog
}
ok, resultLog := BasicSystemdUp("rpcbind")
if !ok {
return false, append(resultLog, "[installNfsOnlineExec] - start rpcbind.service failed !")
}
} }
return true, nil return true, nil
@@ -1134,36 +1181,42 @@ func (op *AgentOsOperator) installNfsOnlineExec() (bool, []string) {
func (op *AgentOsOperator) installNFSOfflineExec() (bool, []string) { func (op *AgentOsOperator) installNFSOfflineExec() (bool, []string) {
log.InfoF("[installNFSOfflineExec] - start to install nfs-client offline !") log.InfoF("[installNFSOfflineExec] - start to install nfs-client offline !")
BasicCreateFolder("/root/install") BasicCreateFolder("/root/wdd")
// check for version // check for version
executor, i := HardCodeCommandExecutor("grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '\"' | sed 's/ /-/g'") //executor, i := HardCodeCommandExecutor("grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '\"' | sed 's/ /-/g'")
if !executor { //if !executor {
return false, append(i, "[installNFSOfflineExec]- get offline package name suffix error !") // return false, append(i, "[installNFSOfflineExec]- get offline package name suffix error !")
} //}
nfsClientOfflinePackageName := "nfs-client-" + op.AgentArch + "-" + i[0] + ".tar.gz" // 2024年1月19日 new version
nfsClientOfflinePackageName := "nfs-client-" + op.AgentArch + "-" + op.AgentServerInfo.Platform + "-" + op.AgentServerInfo.PlatformVersion + ".tar.gz"
// download from oss // download from oss
nfsClientOfflinePackageOSSUrl := op.OssOfflinePrefix + nfsClientOfflinePackageName nfsClientOfflinePackageOSSUrl := op.OssOfflinePrefix + nfsClientOfflinePackageName
log.InfoF("[installNFSOfflineExec]- start to download nfs-client offline package from => %s", nfsClientOfflinePackageOSSUrl) log.InfoF("[installNFSOfflineExec]- start to download nfs-client offline package from => %s", nfsClientOfflinePackageOSSUrl)
ok, resultLog := BasicDownloadFile(nfsClientOfflinePackageOSSUrl, "/root/install/"+nfsClientOfflinePackageName)
ok, resultLog := BasicDownloadFile(nfsClientOfflinePackageOSSUrl, "/root/wdd/"+nfsClientOfflinePackageName)
if !ok { if !ok {
return false, append(resultLog, "[installNFSOfflineExec]- download nfs-client offline package error !", nfsClientOfflinePackageOSSUrl) return false, append(resultLog, "[installNFSOfflineExec]- download nfs-client offline package error !", nfsClientOfflinePackageOSSUrl)
} }
BasicRemoveFolderComplete("/root/install/tmp") BasicRemoveFolderComplete("/root/wdd/tmp")
// unzip // unzip
AllCommandExecutor([]string{ AllCommandExecutor([]string{
"tar", "tar",
"-zvxf", "-zvxf",
"/root/install/" + nfsClientOfflinePackageName, "/root/wdd/" + nfsClientOfflinePackageName,
"-C", "-C",
"/root/install", "/root/wdd",
}) })
// install // install
BasicPrettyPrint(HardCodeCommandExecutor("dpkg -i /root/install/tmp/nfs-client/*.deb")) if op.IsOsTypeUbuntu {
BasicPrettyPrint(HardCodeCommandExecutor("dpkg -i /root/wdd/tmp/nfs-client/*.deb"))
} else if op.IsOsTypeCentOS {
BasicPrettyPrint(HardCodeCommandExecutor("rpm -ivh /root/wdd/tmp/nfs-client/*.rpm"))
}
ok, resultLog = BasicSystemdUp("nfs") ok, resultLog = BasicSystemdUp("nfs")
if !ok { if !ok {
@@ -1178,13 +1231,32 @@ func (op *AgentOsOperator) installNFSOfflineExec() (bool, []string) {
func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) { func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
if !op.CanAccessInternet {
return op.installNFSServerOfflineExec()
}
if !PureResultSingleExecuteBatch([][]string{
{"mkdir", "-p", nfsDataPath},
{"chmod", "777", nfsDataPath},
}) {
return false, []string{
"[installNfsServerOnlineExec]- create nfs data folder failed !",
}
}
if !BasicFindContentInFile(nfsDataPath, "/etc/exports") {
log.DebugF("[installNfsServerOnlineExec]- add nfs path to /etc/exports !")
nfsExport := nfsDataPath + " *(rw,no_root_squash,no_all_squash,sync)"
if !BasicAppendContentToFile(nfsExport, "/etc/exports") {
return false, []string{
"[installNfsServerOnlineExec]- add nfs path to /etc/exports failed !",
}
}
}
// os // os
if op.IsOsTypeUbuntu { if op.IsOsTypeUbuntu {
if !op.CanAccessInternet {
return op.installNFSServerOfflineExec()
}
// ubuntu // ubuntu
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, true, "nfs-kernel-server", installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, true, "nfs-kernel-server",
"nfs-common") "nfs-common")
@@ -1192,46 +1264,42 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
return false, installLog return false, installLog
} }
if !PureResultSingleExecuteBatch([][]string{ // restart nfs-server
{"mkdir", "-p", nfsDataPath}, up, resultLog := BasicSystemdUp("nfs-kernel-server")
{"chmod", "777", nfsDataPath}, if !up {
}) { msg := "[installNfsServerOnlineExec]- nfs-kernel-server start error"
return false, []string{ log.Error(msg)
"[installNfsServerOnlineExec]- create nfs data folder failed !", return false, append(resultLog, msg)
}
} }
if !BasicGrepItemInFile(nfsDataPath, "/etc/exports") { } else if op.IsOsTypeCentOS {
log.DebugF("[installNfsServerOnlineExec]- add nfs path to /etc/exports !") // ubuntu
installOk, installLog := BasicInstallSoftwares(op.InstallCommandPrefix, true, "nfs-utils")
nfsExport := nfsDataPath + " *(rw,no_root_squash,no_all_squash,sync)" if !installOk {
if !BasicAppendContentToFile(nfsExport, "/etc/exports") { return false, installLog
return false, []string{
"[installNfsServerOnlineExec]- add nfs path to /etc/exports failed !",
}
}
} }
// restart nfs-server // restart nfs-server
AllCompleteExecutor([][]string{ up, resultLog := BasicSystemdUp("rpcbind")
{ if !up {
"systemctl", msg := "[installNfsServerOnlineExec]- rpcbind start error"
"restart", log.Error(msg)
"nfs-kernel-server", return false, append(resultLog, msg)
},
{
"systemctl",
"restart",
"nfs",
},
})
ok, i := HardCodeCommandExecutor("rpcinfo -p localhost")
if !ok {
return false, append(i,
"installNfsServerOnlineExec] - rpc info error !",
"please check nfs server installation")
} }
up, resultLog = BasicSystemdUp("nfs-server")
if !up {
msg := "[installNfsServerOnlineExec]- nfs-server start error"
log.Error(msg)
return false, append(resultLog, msg)
}
}
ok, i := HardCodeCommandExecutor("rpcinfo -p localhost")
if !ok {
return false, append(i,
"installNfsServerOnlineExec] - rpc info error !",
"please check nfs server installation")
} }
return true, nil return true, nil
@@ -1240,43 +1308,39 @@ func (op *AgentOsOperator) installNfsServerOnlineExec() (bool, []string) {
func (op *AgentOsOperator) installNFSServerOfflineExec() (bool, []string) { func (op *AgentOsOperator) installNFSServerOfflineExec() (bool, []string) {
log.InfoF("[installNFSServerOfflineExec] - start to install nfs server offline !") log.InfoF("[installNFSServerOfflineExec] - start to install nfs server offline !")
if !BasicCreateFolder("/root/install") { if !BasicCreateFolder("/root/wdd") {
return false, []string{ return false, []string{
"[installNFSServerOfflineExec] - create install folder error !", "[installNFSServerOfflineExec] - create install folder error !",
} }
} }
// check for the version // check for the version
executor, i := HardCodeCommandExecutor("grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '\"' | sed 's/ /-/g'") //executor, i := HardCodeCommandExecutor("grep PRETTY_NAME /etc/os-release | cut -d= -f2 | tr -d '\"' | sed 's/ /-/g'")
if !executor { //if !executor {
return false, append(i, "[installNFSServerOfflineExec]- get offline package name suffix error !") // return false, append(i, "[installNFSServerOfflineExec]- get offline package name suffix error !")
} //}
nfsServerOfflinePackageName := "nfs-server-" + op.AgentArch + "-" + i[0] + ".tar.gz"
nfsServerOfflinePackageName := "nfs-server-" + op.AgentArch + "-" + op.AgentServerInfo.Platform + "-" + op.AgentServerInfo.PlatformVersion + ".tar.gz"
// download from oss // download from oss
nfsServerOfflinePackageOSSUrl := op.OssOfflinePrefix + nfsServerOfflinePackageName nfsServerOfflinePackageOSSUrl := op.OssOfflinePrefix + nfsServerOfflinePackageName
log.InfoF("[installNFSServerOfflineExec]- start to download nfs-server offline package from => %s", nfsServerOfflinePackageOSSUrl) log.InfoF("[installNFSServerOfflineExec]- start to download nfs-server offline package from => %s", nfsServerOfflinePackageOSSUrl)
ok, resultLog := BasicDownloadFile(nfsServerOfflinePackageOSSUrl, "/root/install/"+nfsServerOfflinePackageName) ok, resultLog := BasicDownloadFile(nfsServerOfflinePackageOSSUrl, "/root/wdd/"+nfsServerOfflinePackageName)
if !ok { if !ok {
return false, append(resultLog, "[installNFSServerOfflineExec]- download nfs-server offline package error !", nfsServerOfflinePackageOSSUrl) return false, append(resultLog, "[installNFSServerOfflineExec]- download nfs-server offline package error !", nfsServerOfflinePackageOSSUrl)
} }
BasicRemoveFolderComplete("/root/install/tmp") BasicRemoveFolderComplete("/root/wdd/tmp")
// unzip // unzip
AllCommandExecutor([]string{ AllCommandExecutor([]string{
"tar", "tar",
"-zvxf", "-zvxf",
"/root/install/" + nfsServerOfflinePackageName, "/root/wdd/" + nfsServerOfflinePackageName,
"-C", "-C",
"/root/install", "/root/wdd",
}) })
// install
BasicPrettyPrint(HardCodeCommandExecutor(
"dpkg -i /root/install/tmp/nfs-server/*.deb",
))
if !PureResultSingleExecuteBatch([][]string{ if !PureResultSingleExecuteBatch([][]string{
{"mkdir", "-p", nfsDataPath}, {"mkdir", "-p", nfsDataPath},
{"chmod", "777", nfsDataPath}, {"chmod", "777", nfsDataPath},
@@ -1286,7 +1350,7 @@ func (op *AgentOsOperator) installNFSServerOfflineExec() (bool, []string) {
} }
} }
if !BasicGrepItemInFile(nfsDataPath, "/etc/exports") { if !BasicFindContentInFile(nfsDataPath, "/etc/exports") {
log.DebugF("[installNFSServerOfflineExec]- add nfs path to /etc/exports !") log.DebugF("[installNFSServerOfflineExec]- add nfs path to /etc/exports !")
nfsExport := nfsDataPath + " *(rw,no_root_squash,no_all_squash,sync)" nfsExport := nfsDataPath + " *(rw,no_root_squash,no_all_squash,sync)"
@@ -1297,21 +1361,41 @@ func (op *AgentOsOperator) installNFSServerOfflineExec() (bool, []string) {
} }
} }
AllCompleteExecutor([][]string{ // install
{ if op.IsOsTypeUbuntu {
"systemctl", BasicPrettyPrint(HardCodeCommandExecutor(
"restart", "dpkg -i /root/wdd/tmp/nfs-server/*.deb",
"nfs-kernel-server", ))
},
{
"systemctl",
"restart",
"nfs",
},
})
ok, i = HardCodeCommandExecutor("rpcinfo -p localhost") up, resultLog := BasicSystemdUp("nfs-kernel-server")
if !ok { if !up {
msg := "[installNfsServerOnlineExec]- nfs-kernel-server start error"
log.Error(msg)
return false, append(resultLog, msg)
}
} else if op.IsOsTypeCentOS {
BasicPrettyPrint(HardCodeCommandExecutor(
"rpm -ivh /root/wdd/tmp/nfs-server/*.rpm",
))
// restart nfs-server
up, resultLog := BasicSystemdUp("rpcbind")
if !up {
msg := "[installNfsServerOnlineExec]- rpcbind start error"
log.Error(msg)
return false, append(resultLog, msg)
}
up, resultLog = BasicSystemdUp("nfs-server")
if !up {
msg := "[installNfsServerOnlineExec]- nfs-server start error"
log.Error(msg)
return false, append(resultLog, msg)
}
}
rpcinfoOK, i := HardCodeCommandExecutor("rpcinfo -p localhost")
if !rpcinfoOK {
return false, append(i, return false, append(i,
"[installNFSServerOfflineExec] - rpc info error !", "[installNFSServerOfflineExec] - rpc info error !",
"please check nfs server installation") "please check nfs server installation")
@@ -1433,7 +1517,7 @@ func (op *AgentOsOperator) installHarborExec() (bool, []string) {
} }
} }
if strings.HasPrefix(op.AgentArch, "arm") { if strings.HasPrefix(op.AgentArch, "arm64") {
return false, []string{ return false, []string{
"[install harbor] - script do not support for aarch64 version of harbor installation !", "[install harbor] - script do not support for aarch64 version of harbor installation !",
} }
@@ -1902,7 +1986,10 @@ func (op *AgentOsOperator) chronyToMaster(args []string) [][]string {
func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) { func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
if !op.IsOsTypeUbuntu { if op.IsOsTypeCentOS {
// todo
return false, []string{ return false, []string{
"[chronyToMasterExec] - do not support none ubuntu os !", "[chronyToMasterExec] - do not support none ubuntu os !",
} }

View File

@@ -150,6 +150,52 @@ func BasicFindContentInFile(content string, fileName string) bool {
return false return false
} }
func BasicFindDeleteContendLineInFile(content string, fileName string) bool {
// Open the file
file, err := os.Open(fileName)
if err != nil {
log.ErrorF("[FindDeleteContendLineInFile] - file not exits ")
return false
}
defer file.Close()
// Create a scanner to read the file line by line
scanner := bufio.NewScanner(file)
// Set the split function for the scanner
scanner.Split(bufio.ScanLines)
// 创建一个新的文件内容变量
var newContent string
// Iterate over the lines of the file
for scanner.Scan() {
// Get the current line
line := scanner.Text()
// Check if the current line contains the search term
if !strings.Contains(line, content) {
newContent += line + "\n"
}
}
// Check for any errors that occurred during scanning
if err := scanner.Err(); err != nil {
log.ErrorF("[BasicFindContentInFile] - scanner error ! %s", err.Error())
return false
}
// 将修改后的内容写回文件
err = os.WriteFile(fileName, []byte(newContent), os.ModePerm)
if err != nil {
log.ErrorF("[FindDeleteContendLineInFile] - write file %s error with contend %s", fileName, newContent)
return false
}
return true
}
func BasicDockerImageExists(imageName, imageVersion string) bool { func BasicDockerImageExists(imageName, imageVersion string) bool {
if !BasicCommandExistByPath("docker") { if !BasicCommandExistByPath("docker") {

View File

@@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
func BuildAgentOsOperator(ossOfflinePrefix string) *AgentOsOperator { func BuildAgentOsOperator(agentInfo *status.AgentInfo, ossOfflinePrefix string) *AgentOsOperator {
AgentOsOperatorCache = &AgentOsOperator{ AgentOsOperatorCache = &AgentOsOperator{
InstallCommandPrefix: []string{ InstallCommandPrefix: []string{
@@ -25,7 +25,7 @@ func BuildAgentOsOperator(ossOfflinePrefix string) *AgentOsOperator {
} }
// os type // os type
detectByAgentStatusInfo(AgentOsOperatorCache) detectByAgentStatusInfo(agentInfo, AgentOsOperatorCache)
// internet // internet
detectByInternet(AgentOsOperatorCache) detectByInternet(AgentOsOperatorCache)
@@ -33,8 +33,11 @@ func BuildAgentOsOperator(ossOfflinePrefix string) *AgentOsOperator {
return AgentOsOperatorCache return AgentOsOperatorCache
} }
func detectByAgentStatusInfo(os *AgentOsOperator) { func detectByAgentStatusInfo(agentInfo *status.AgentInfo, os *AgentOsOperator) {
agentInfo := status.ReportAgentInfo() if agentInfo == nil {
log.WarnF("[detectByAgentStatusInfo] - agentInfo from status module is nil, roll back to traditional way!")
// detectByOsType()
}
bytes, _ := json.Marshal(agentInfo) bytes, _ := json.Marshal(agentInfo)
log.DebugF("[detectByAgentStatusInfo] - agent info is => %s", string(bytes)) log.DebugF("[detectByAgentStatusInfo] - agent info is => %s", string(bytes))

View File

@@ -40,7 +40,7 @@ func TestFindDeploymentReplicasSmallerThanN(t *testing.T) {
} }
func TestFindCmiiMiddlewarePodInterface(t *testing.T) { func TestFindCmiiMiddlewarePodInterface(t *testing.T) {
middlewarePodInterface := FindCmiiMiddlewarePodInterface(devFlight) middlewarePodInterface := FindCmiiMiddlewarePodInterface(integration)
for _, middlePod := range middlewarePodInterface { for _, middlePod := range middlewarePodInterface {
println() println()

View File

@@ -1,26 +1,31 @@
package register package register
type AgentServerInfo struct { type AgentServerInfo struct {
ServerName string `json:"serverName" yaml:"serverName"` ServerName string `json:"serverName" yaml:"serverName"`
ServerIPPbV4 string `json:"serverIpPbV4" yaml:"serverIpPbV4"` ServerIPPbV4 string `json:"serverIpPbV4" yaml:"serverIpPbV4"`
ServerIPInV4 string `json:"serverIpInV4" yaml:"serverIpInV4"` ServerIPInV4 string `json:"serverIpInV4" yaml:"serverIpInV4"`
ServerIPPbV6 string `json:"serverIpPbV6" yaml:"serverIpPbV6"` ServerIPPbV6 string `json:"serverIpPbV6" yaml:"serverIpPbV6"`
ServerIPInV6 string `json:"serverIpInV6" yaml:"serverIpInV6"` ServerIPInV6 string `json:"serverIpInV6" yaml:"serverIpInV6"`
Location string `json:"location" yaml:"location"` Location string `json:"location" yaml:"location"`
Provider string `json:"provider" yaml:"provider"` Provider string `json:"provider" yaml:"provider"`
ManagePort string `json:"managePort" yaml:"managePort"` ManagePort string `json:"managePort" yaml:"managePort"`
CPUCore string `json:"cpuCore" yaml:"cpuCore"` CPUCore string `json:"cpuCore" yaml:"cpuCore"`
CPUBrand string `json:"cpuBrand" yaml:"cpuBrand"` CPUBrand string `json:"cpuBrand" yaml:"cpuBrand"`
OSInfo string `json:"osInfo" yaml:"osInfo"` OSInfo string `json:"osInfo" yaml:"osInfo"`
OSKernelInfo string `json:"osKernelInfo" yaml:"osKernelInfo"` OSKernelInfo string `json:"osKernelInfo" yaml:"osKernelInfo"`
TCPControl string `json:"tcpControl" yaml:"tcpControl"` TCPControl string `json:"tcpControl" yaml:"tcpControl"`
Virtualization string `json:"virtualization" yaml:"virtualization"` Virtualization string `json:"virtualization" yaml:"virtualization"`
IoSpeed string `json:"ioSpeed" yaml:"ioSpeed"` Platform string `json:"platform"` // ex: ubuntu, linuxmint
MemoryTotal string `json:"memoryTotal" yaml:"memoryTotal"` PlatformFamily string `json:"platformFamily"` // ex: debian, rhel
DiskTotal string `json:"diskTotal" yaml:"diskTotal"` PlatformVersion string `json:"platformVersion"` // version of the complete OS
DiskUsage string `json:"diskUsage" yaml:"diskUsage"` KernelVersion string `json:"kernelVersion"` // version of the OS kernel (if available)
Comment string `json:"comment" yaml:"comment"` KernelArch string `json:"kernelArch"` // native cpu architecture queried at runtime, as returned by `uname -m` or empty string in case of error
MachineID string `json:"machineId" yaml:"machineId"` IoSpeed string `json:"ioSpeed" yaml:"ioSpeed"`
AgentVersion string `json:"agentVersion" yaml:"agentVersion"` MemoryTotal string `json:"memoryTotal" yaml:"memoryTotal"`
TopicName string `json:"topicName" yaml:"topicName"` DiskTotal string `json:"diskTotal" yaml:"diskTotal"`
DiskUsage string `json:"diskUsage" yaml:"diskUsage"`
Comment string `json:"comment" yaml:"comment"`
MachineID string `json:"machineId" yaml:"machineId"`
AgentVersion string `json:"agentVersion" yaml:"agentVersion"`
TopicName string `json:"topicName" yaml:"topicName"`
} }

View File

@@ -13,6 +13,11 @@ public enum BaseFunctionEnum {
), ),
DISABLE_SELINUX(
"DISABLE_SELINUX",
"关闭SELinux"
),
MODIFY_HOSTNAME( MODIFY_HOSTNAME(
"modifyHostname", "modifyHostname",
"修改主机名称, args 主机名" "修改主机名称, args 主机名"