[Agent] [Executor] 新增Systemd的部分

This commit is contained in:
zeaslity
2023-10-19 15:48:04 +08:00
parent 328247eeae
commit d9c1c0fb91
4 changed files with 133 additions and 14 deletions

View File

@@ -93,18 +93,33 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
serviceName = serviceName + ".service"
}
systemdFilePath := []string{
"/lib/systemd/system/",
"/etc/systemd/system",
}
// 检查是否存在
execute := PureResultSingleExecute(
[]string{
"systemctl",
"status",
"-q",
serviceName,
})
if !execute {
var existService bool
for _, s := range systemdFilePath {
resultOk, _ := PipelineCommandExecutor(
[][]string{
{"ls",
s,
},
{
"grep",
serviceName,
},
})
if resultOk {
existService = true
}
}
if !existService {
return true, []string{
serviceName,
"该服务不存在!",
"该服务不存在!",
}
}
@@ -115,6 +130,10 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
"stop",
serviceName,
},
{
"sleep",
"1",
},
{
"systemctl",
"disable",
@@ -127,6 +146,65 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
return resultOK, resultLog
}
func BasicSystemdUp(serviceName string) (ok bool, resultLog []string) {
if !strings.HasSuffix(serviceName, ".service") {
serviceName = serviceName + ".service"
}
systemdFilePath := []string{
"/lib/systemd/system/",
"/etc/systemd/system",
}
// 检查是否存在
var existService bool
for _, s := range systemdFilePath {
resultOk, _ := PipelineCommandExecutor(
[][]string{
{"ls",
s,
},
{
"grep",
serviceName,
},
})
if resultOk {
existService = true
}
}
if !existService {
return true, []string{
serviceName,
"该服务不存在!",
}
}
// 关闭
var shutDownCommand = [][]string{
{
"systemctl",
"start",
serviceName,
},
{
"sleep",
"1",
},
{
"systemctl",
"enable",
serviceName,
},
}
resultOK := PureResultSingleExecuteBatch(shutDownCommand)
return resultOK, resultLog
}
func BasicTransPipelineCommand(pipelineString string) (pipelineCommand [][]string) {
var pipelineCommandC [][]string