[ Server ] [ APP ] - accomplish rke and dashboard
This commit is contained in:
@@ -34,6 +34,59 @@ func BasicCommandExistsBatch(commandNameList []string) (bool, string) {
|
||||
return true, ""
|
||||
}
|
||||
|
||||
// BasicCommandExistByPath 根据路径判定 命令是否存在
|
||||
func BasicCommandExistByPath(commandName string) bool {
|
||||
|
||||
if BasicFileExistInFolder(commandName, "/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "bin", "/snap/bin") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// BasicFileExistInFolder 查询fileName是否存在于目录folderList中,如果存在返回true,不存在返回false
|
||||
func BasicFileExistInFolder(fileName string, folderList ...string) bool {
|
||||
|
||||
for _, folder := range folderList {
|
||||
if BasicFolderExists(folder) {
|
||||
// is folder
|
||||
ok, _ := PipelineCommandExecutor([][]string{
|
||||
{
|
||||
"ls",
|
||||
folder,
|
||||
},
|
||||
{
|
||||
"grep",
|
||||
"-c",
|
||||
fileName,
|
||||
},
|
||||
})
|
||||
if ok {
|
||||
return true
|
||||
}
|
||||
|
||||
} else {
|
||||
// it's a file
|
||||
ok, _ := PipelineCommandExecutor([][]string{
|
||||
{
|
||||
"echo",
|
||||
folder,
|
||||
},
|
||||
{
|
||||
"grep",
|
||||
"-c",
|
||||
fileName,
|
||||
},
|
||||
})
|
||||
if ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// BasicReplace 基础替换命令
|
||||
func BasicReplace(filename string, origin string, replace string) bool {
|
||||
|
||||
@@ -78,6 +131,18 @@ func BasicFileExistAndNotNull(filename string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func BasicFolderExists(folderName string) bool {
|
||||
|
||||
cmd := exec.Command("test", "-d", folderName)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
log.DebugF("目录 %s 不存在!", folderName)
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func BasicCreateFolder(folderName string) bool {
|
||||
cmd := exec.Command("test", "-d", folderName)
|
||||
err := cmd.Run()
|
||||
@@ -115,30 +180,9 @@ func BasicSystemdShutdown(serviceName string) (ok bool, resultLog []string) {
|
||||
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
|
||||
}
|
||||
}
|
||||
existService := BasicFileExistInFolder(serviceName, "/lib/systemd/system/",
|
||||
"/etc/systemd/system")
|
||||
if !existService {
|
||||
return true, []string{
|
||||
serviceName,
|
||||
@@ -175,30 +219,9 @@ 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
|
||||
}
|
||||
}
|
||||
existService := BasicFileExistInFolder(serviceName, "/lib/systemd/system/",
|
||||
"/etc/systemd/system")
|
||||
if !existService {
|
||||
return true, []string{
|
||||
serviceName,
|
||||
@@ -269,7 +292,7 @@ func BasicDownloadFile(downloadUrl, desFile string) (downloadOk bool, resultLog
|
||||
|
||||
// wget or curl download
|
||||
var ok bool
|
||||
if BasicCommandExists("wget") {
|
||||
if BasicCommandExistByPath("wget") {
|
||||
|
||||
ok, resultLog = AllCommandExecutor([]string{
|
||||
"wget",
|
||||
@@ -280,7 +303,7 @@ func BasicDownloadFile(downloadUrl, desFile string) (downloadOk bool, resultLog
|
||||
desFile,
|
||||
})
|
||||
|
||||
} else if BasicCommandExists("curl") {
|
||||
} else if BasicCommandExistByPath("curl") {
|
||||
ok, resultLog = AllCommandExecutor([]string{
|
||||
"curl",
|
||||
"-o",
|
||||
|
||||
@@ -30,7 +30,7 @@ func Execute(em *ExecutionMessage) (bool, []string) {
|
||||
var resultLog []string
|
||||
var err error
|
||||
ok := true
|
||||
executionContent := em.ExecutionType + "==" + strings.Join(em.FuncContent, " - ")
|
||||
executionContent := em.ExecutionType + " == " + strings.Join(em.FuncContent, " - ")
|
||||
|
||||
log.DebugF("em message is => %#v", em)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user