Enhance Docker Installation and Management Commands
- Improved Docker installation process for Ubuntu systems - Added support for dynamic Docker version detection - Enhanced Docker local and online installation commands - Implemented more robust Docker removal functionality - Updated Docker installation to use system-specific package sources - Added better error handling and logging for Docker operations - Refined Docker service startup and configuration checks
This commit is contained in:
@@ -3,12 +3,10 @@ package op
|
||||
import (
|
||||
"agent-wdd/config"
|
||||
"agent-wdd/log"
|
||||
"agent-wdd/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -60,8 +58,11 @@ func (op *PackageOperator) Install(tools []string) bool {
|
||||
ok, result := SingleLineCommandExecutor(append(AgentPackOperator.installPrefix, tool))
|
||||
if !ok {
|
||||
log.Error("[install] failed! => %s", tool)
|
||||
utils.BeautifulPrint(result)
|
||||
}
|
||||
|
||||
// 打印安装的过程内容
|
||||
beautifulPrintListWithTitle(result, fmt.Sprintf("安装 %s 的过程内容", tool))
|
||||
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -71,21 +72,29 @@ func (op *PackageOperator) Install(tools []string) bool {
|
||||
func (op *PackageOperator) PackageInit() bool {
|
||||
log.Info("PackageInit !")
|
||||
|
||||
// beautifulPrintListWithTitle(config.ConfigCache)
|
||||
|
||||
// package init
|
||||
os := config.ConfigCache.Agent.OS
|
||||
|
||||
if os.PackInit {
|
||||
log.Info("PackageInit already done! skip!")
|
||||
return true
|
||||
}
|
||||
|
||||
// 判定本机的包管理Operator
|
||||
ok := generatePackageOperator()
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
// package init
|
||||
os := config.ConfigCache.Agent.OS
|
||||
osFamily := strings.ToLower(os.OsFamily)
|
||||
os.PackInit = true
|
||||
os.SaveConfig()
|
||||
|
||||
if strings.Contains(osFamily, "ubuntu") || strings.Contains(osFamily, "debian") {
|
||||
if os.IsUbuntuType {
|
||||
ok, resultLog := SingleLineCommandExecutor(aptPackageOperator.initCommand)
|
||||
if !ok {
|
||||
log.Error("APT init failed! please check !")
|
||||
utils.BeautifulPrint(resultLog)
|
||||
log.Error("APT init failed! please check ! %s", resultLog)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +102,23 @@ func (op *PackageOperator) PackageInit() bool {
|
||||
|
||||
}
|
||||
|
||||
func (op *PackageOperator) PackageInitForce() bool {
|
||||
|
||||
log.Info("PackageInitForce !")
|
||||
|
||||
os := config.ConfigCache.Agent.OS
|
||||
|
||||
if os.IsUbuntuType {
|
||||
ok, resultLog := SingleLineCommandExecutor(aptPackageOperator.initCommand)
|
||||
if !ok {
|
||||
log.Error("APT init failed! please check ! %s", resultLog)
|
||||
}
|
||||
log.Info("APT init success! %s", resultLog)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (op *PackageOperator) Remove(tools []string) {
|
||||
// 判定本机的包管理Operator
|
||||
generatePackageOperator()
|
||||
@@ -102,7 +128,7 @@ func (op *PackageOperator) Remove(tools []string) {
|
||||
ok, result := SingleLineCommandExecutor(append(AgentPackOperator.removePrefix, tool))
|
||||
if !ok {
|
||||
log.Error("[remove] failed! => %s", tool)
|
||||
utils.BeautifulPrint(result)
|
||||
beautifulPrintListWithTitle(result, fmt.Sprintf("移除 %s 的过程内容", tool))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +138,7 @@ func generatePackageOperator() bool {
|
||||
|
||||
// cache return
|
||||
if AgentPackOperator.initCommand != nil {
|
||||
log.Info("PackageOperator init success! %v", AgentPackOperator.initCommand)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -125,13 +152,14 @@ func generatePackageOperator() bool {
|
||||
os := config.ConfigCache.Agent.OS
|
||||
if os.Hostname == "" {
|
||||
os.Gather()
|
||||
|
||||
os.SaveConfig()
|
||||
}
|
||||
|
||||
if os.IsUbuntuType {
|
||||
log.Info("Ubuntu type detected! use apt package operator!")
|
||||
AgentPackOperator = aptPackageOperator
|
||||
} else {
|
||||
log.Info("Other type detected! use yum package operator!")
|
||||
AgentPackOperator = yumPackageOperator
|
||||
}
|
||||
|
||||
@@ -195,3 +223,13 @@ func CommandExistsByPath(command string) bool {
|
||||
ok, _ := SingleLineCommandExecutor([]string{"find", "/usr/bin", "/usr/local/bin", "-name", command})
|
||||
return ok
|
||||
}
|
||||
|
||||
func beautifulPrintListWithTitle(contend []string, title string) {
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println(">>>>>>>> " + title + " <<<<<<<<")
|
||||
for _, line := range contend {
|
||||
fmt.Println(line)
|
||||
}
|
||||
fmt.Println(">>>>>>>> end <<<<<<<<")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user