[agent-go]-简化Agent 剔除Harbor K8s Image相关的内容
This commit is contained in:
@@ -583,6 +583,34 @@ func BasicSystemdUp(serviceName string) (ok bool, resultLog []string) {
|
||||
return resultOK, resultLog
|
||||
}
|
||||
|
||||
// BasicSystemdRestart 使用Systemd 重启 服务,会判定服务器是否存在
|
||||
func BasicSystemdRestart(serviceName string) (ok bool, resultLog []string) {
|
||||
|
||||
if !strings.HasSuffix(serviceName, ".service") {
|
||||
serviceName = serviceName + ".service"
|
||||
}
|
||||
// 检查是否存在
|
||||
existService := BasicFileExistInFolder(serviceName, "/lib/systemd/system/",
|
||||
"/etc/systemd/system")
|
||||
if !existService {
|
||||
return true, []string{
|
||||
serviceName,
|
||||
"该服务不存在!",
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭
|
||||
var restartCommand = []string{
|
||||
"systemctl",
|
||||
"restart",
|
||||
serviceName,
|
||||
}
|
||||
|
||||
resultOK := PureResultSingleExecute(restartCommand)
|
||||
|
||||
return resultOK, resultLog
|
||||
}
|
||||
|
||||
// BasicTransPipelineCommand 转换手写的管道命令为可执行的形式
|
||||
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
|
||||
|
||||
@@ -839,10 +867,8 @@ func BasicAppendContentToFile(content string, targetFile string) bool {
|
||||
// BasicAppendOverwriteContentToFile 向目标文件中写入一些内容,覆盖源文件
|
||||
func BasicAppendOverwriteContentToFile(content string, targetFile string) bool {
|
||||
|
||||
err := os.Remove(targetFile)
|
||||
if err != nil {
|
||||
log.WarnF("[BasicAppendOverwriteContentToFile] - Error removing file: %s , error is %s", targetFile, err.Error())
|
||||
}
|
||||
// 删除文件,直接覆写
|
||||
_ = os.Remove(targetFile)
|
||||
|
||||
return BasicAppendContentToFile(content, targetFile)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user