[ Agent ] [ Executor ] - 新增chrony部分

This commit is contained in:
zeaslity
2023-11-08 11:33:18 +08:00
parent d0309a69fa
commit 81363abf20
3 changed files with 122 additions and 9 deletions

View File

@@ -77,6 +77,9 @@ func (op *AgentOsOperator) Exec(baseFuncName string, funcArgs ...string) (bool,
case "installHarbor": case "installHarbor":
resultOk, errorLog = op.installHarborExec() resultOk, errorLog = op.installHarborExec()
break break
case "installChrony":
resultOk, errorLog = op.installChronyExec()
break
case "chronyToPublicNTP": case "chronyToPublicNTP":
resultOk, errorLog = op.chronyToPublicNTPExec() resultOk, errorLog = op.chronyToPublicNTPExec()
break break
@@ -254,7 +257,7 @@ func (op *AgentOsOperator) enableSwap() [][]string {
} }
func (op *AgentOsOperator) enableSwapExec() (bool, []string) { func (op *AgentOsOperator) enableSwapExec() (bool, []string) {
return false, nil return true, nil
} }
func (op *AgentOsOperator) disableSwap() [][]string { func (op *AgentOsOperator) disableSwap() [][]string {
@@ -855,7 +858,7 @@ func (op *AgentOsOperator) installHelm() [][]string {
} }
func (op *AgentOsOperator) installHelmExec() (bool, []string) { func (op *AgentOsOperator) installHelmExec() (bool, []string) {
return false, nil return true, nil
} }
func (op *AgentOsOperator) modifyDockerConfig(args []string) [][]string { func (op *AgentOsOperator) modifyDockerConfig(args []string) [][]string {
@@ -891,7 +894,7 @@ func (op *AgentOsOperator) modifyDockerConfig(args []string) [][]string {
} }
func (op *AgentOsOperator) modifyDockerConfigExec(args []string) (bool, []string) { func (op *AgentOsOperator) modifyDockerConfigExec(args []string) (bool, []string) {
return false, nil return true, nil
} }
func (op *AgentOsOperator) installHarbor() [][]string { func (op *AgentOsOperator) installHarbor() [][]string {
@@ -961,7 +964,7 @@ func (op *AgentOsOperator) installHarbor() [][]string {
} }
func (op *AgentOsOperator) installHarborExec() (bool, []string) { func (op *AgentOsOperator) installHarborExec() (bool, []string) {
return false, nil return true, nil
} }
func (op *AgentOsOperator) chronyToPublicNTP() [][]string { func (op *AgentOsOperator) chronyToPublicNTP() [][]string {
@@ -1048,7 +1051,112 @@ func (op *AgentOsOperator) chronyToPublicNTP() [][]string {
} }
func (op *AgentOsOperator) chronyToPublicNTPExec() (bool, []string) { func (op *AgentOsOperator) chronyToPublicNTPExec() (bool, []string) {
return false, nil
var chronyFile string
if op.IsOsTypeUbuntu {
chronyFile = "/etc/chrony/chrony.conf"
} else {
chronyFile = "/etc/chrony.conf"
}
ok, resultLog := AllCompleteExecutor([][]string{
{
"sed",
"-i",
"$ a allow all",
chronyFile,
},
{
"sed",
"-i",
"s/pool ntp.ubuntu.com iburst/server ntp2.aliyun.com iburst/g",
chronyFile,
},
{
"systemctl",
"restart",
"chronyd",
},
{
"timedatectl",
"set-timezone",
"Asia/Shanghai",
},
{
"sleep",
"2",
}})
if !ok {
return false, resultLog
}
_, l := AllCompleteExecutor([][]string{
{
"chronyc",
"-n",
"sources",
"-v",
},
{
"chronyc",
"tracking",
},
{
"chronyc",
"clients",
},
})
// check chrony
return true, l
}
// installChronyExec make sure chrony is installed
func (op *AgentOsOperator) installChronyExec() (bool, []string) {
// uninstall systemd-timesyncd.service
ok, resultLog := BasicSystemdShutdown("systemd-timesyncd.service")
if !ok {
return false, resultLog
}
//resultOk, l := AllCommandExecutor(
// append(
// op.RemoveCommandPrefix,
// "systemd-timesyncd.service",
// ),
//)
//if !resultOk{
// return false, l
//}
// install chrony
resultOk, l := AllCommandExecutor(
append(
op.InstallCommandPrefix,
"chrony",
),
)
if !resultOk {
return false, l
}
// check installation
fileExistAndNotNull := BasicFileExistAndNotNull("/etc/chrony/chrony.conf")
if !fileExistAndNotNull {
return false, []string{
"chrony config file is null !",
"chrony installation is failed !",
"please check!"}
}
up, log2 := BasicSystemdUp("chrony.service")
if !up {
return false, log2
}
return true, nil
} }
func (op *AgentOsOperator) chronyToMaster(args []string) [][]string { func (op *AgentOsOperator) chronyToMaster(args []string) [][]string {
@@ -1089,7 +1197,7 @@ func (op *AgentOsOperator) chronyToMaster(args []string) [][]string {
} }
func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) { func (op *AgentOsOperator) chronyToMasterExec(args []string) (bool, []string) {
return false, nil return true, nil
} }
func (op *AgentOsOperator) installZSH() [][]string { func (op *AgentOsOperator) installZSH() [][]string {
@@ -1368,7 +1476,7 @@ func (op *AgentOsOperator) modifySshPort(args []string) [][]string {
} }
func (op *AgentOsOperator) modifySshPortExec(args []string) (bool, []string) { func (op *AgentOsOperator) modifySshPortExec(args []string) (bool, []string) {
return false, nil return true, nil
} }
func (op *AgentOsOperator) openBBR() [][]string { func (op *AgentOsOperator) openBBR() [][]string {
@@ -1377,7 +1485,7 @@ func (op *AgentOsOperator) openBBR() [][]string {
} }
func (op *AgentOsOperator) openBBRExec() (bool, []string) { func (op *AgentOsOperator) openBBRExec() (bool, []string) {
return false, nil return true, nil
} }
func (op *AgentOsOperator) ok(args []string) [][]string { func (op *AgentOsOperator) ok(args []string) [][]string {

View File

@@ -44,6 +44,10 @@ public enum BaseFunctionEnum {
"安装Harbor, 默认为2.1.0版本" "安装Harbor, 默认为2.1.0版本"
), ),
INSTALL_CHRONY(
"installChrony",
"安装Chrony服务器"
),
CHRONY_TO_PUBLIC_NTP( CHRONY_TO_PUBLIC_NTP(
"chronyToPublicNTP", "chronyToPublicNTP",

View File

@@ -62,8 +62,9 @@ public class FuncServiceImpl implements FuncService {
} }
if (syncResultLog if (syncResultLog
.get(0) .get(syncResultLog.size() - 1)
.endsWith("true")) { .endsWith("true")) {
log.debug( log.debug(
"基本脚本调用成功 => {}", "基本脚本调用成功 => {}",
syncResultLog syncResultLog