愉快的使用cursor
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"agent-wdd/cmd/beans"
|
||||
"agent-wdd/config"
|
||||
"agent-wdd/log"
|
||||
"agent-wdd/op"
|
||||
"agent-wdd/utils"
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -18,9 +20,18 @@ var (
|
||||
"deltarpm", "net-tools", "iputils", "bind-utils", "lsof", "curl", "wget", "vim", "mtr", "htop",
|
||||
}
|
||||
|
||||
dockerLocalInstallPath = "/root/wdd/docker-20.10.15.tgz" // 本地安装docker的文件路径
|
||||
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
|
||||
)
|
||||
|
||||
func init() {
|
||||
switch runtime.GOARCH {
|
||||
case "amd64":
|
||||
dockerLocalInstallPath = "/root/wdd/docker-amd64-20.10.15.tgz" // 本地安装docker的文件路径
|
||||
case "arm64":
|
||||
dockerLocalInstallPath = "/root/wdd/docker-arm64-20.10.15.tgz" // 本地安装docker的文件路径
|
||||
}
|
||||
}
|
||||
|
||||
// 添加base子命令
|
||||
func addBaseSubcommands(cmd *cobra.Command) {
|
||||
// 1.1 docker
|
||||
@@ -88,7 +99,7 @@ func addDockerSubcommands(cmd *cobra.Command) {
|
||||
}
|
||||
|
||||
// 没有传递参数,使用默认参数
|
||||
version := "26.0.7"
|
||||
version := "20.10.15"
|
||||
log.Info("Installing Docker version: %s", version)
|
||||
|
||||
// 安装docker
|
||||
@@ -113,6 +124,9 @@ func addDockerSubcommands(cmd *cobra.Command) {
|
||||
Short: "本地安装Docker",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
log.Info("Installing Docker from local file: %s", dockerLocalInstallPath)
|
||||
|
||||
exist := utils.FileExistAndNotNull(dockerLocalInstallPath)
|
||||
if !exist {
|
||||
log.Error("Docker local install file not found: %s", dockerLocalInstallPath)
|
||||
@@ -120,7 +134,72 @@ func addDockerSubcommands(cmd *cobra.Command) {
|
||||
}
|
||||
|
||||
// 解压文件
|
||||
utils.Unzip(dockerLocalInstallPath, "/root/wdd")
|
||||
utils.UnzipFile(dockerLocalInstallPath, "/root/wdd")
|
||||
|
||||
// 安装docker
|
||||
err := utils.MoveFolerToAnother("/root/wdd/docker", "/usr/bin")
|
||||
if err != nil {
|
||||
log.Error("Failed to move Docker binaries: %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 设置权限
|
||||
chmodCmd := []string{"chmod", "777", "-R", "/usr/bin/docker*"}
|
||||
ok, resultLog := op.SingleLineCommandExecutor(chmodCmd)
|
||||
if !ok {
|
||||
log.Error("Failed to set permissions for Docker binaries: %s", resultLog)
|
||||
return
|
||||
}
|
||||
|
||||
// 配置并启动Docker服务
|
||||
// systemd daemonize docker
|
||||
utils.AppendOverwriteContentToFile(beans.ContainerdDaemonService, beans.ContainerdServiceFile)
|
||||
if !utils.FileExistAndNotNull(beans.ContainerdServiceFile) {
|
||||
log.Error("docker deamon file not exists !")
|
||||
}
|
||||
utils.AppendOverwriteContentToFile(beans.DockerSocketDaemonService, beans.DockerSocketFile)
|
||||
if !utils.FileExistAndNotNull(beans.DockerSocketFile) {
|
||||
log.Error("docker deamon file not exists !")
|
||||
}
|
||||
utils.AppendOverwriteContentToFile(beans.DockerDaemonService, beans.DockerServiceFile)
|
||||
if !utils.FileExistAndNotNull(beans.DockerServiceFile) {
|
||||
log.Error("docker deamon file not exists !")
|
||||
}
|
||||
log.Info("docker dameon file append success !")
|
||||
|
||||
ok, resultLog = op.SystemdDaemonReload()
|
||||
if !ok {
|
||||
log.Error("daemon reload error ! %s", resultLog)
|
||||
return
|
||||
}
|
||||
|
||||
op.SingleLineCommandExecutor([]string{"systemctl", "unmask", "containerd"})
|
||||
op.SingleLineCommandExecutor([]string{"systemctl", "unmask", "docker.socket"})
|
||||
op.SingleLineCommandExecutor([]string{"systemctl", "unmask", "docker"})
|
||||
|
||||
op.SingleLineCommandExecutor([]string{"groupadd", "docker"})
|
||||
op.SingleLineCommandExecutor([]string{"usermod", "-aG", "docker", "root"})
|
||||
op.SingleLineCommandExecutor([]string{"newgrp", "docker"})
|
||||
|
||||
systemdUp, resultLog := op.SystemdUp("containerd")
|
||||
if !systemdUp {
|
||||
log.Error("[InstallDockerBastion] - start containerd service error ! %s", resultLog)
|
||||
return
|
||||
}
|
||||
|
||||
ok, resultLog = op.SystemdUp("docker.socket")
|
||||
if !ok {
|
||||
log.Error("[InstallDockerBastion] - start docker.socket error ! %s", resultLog)
|
||||
return
|
||||
}
|
||||
|
||||
ok, resultLog = op.SystemdUp("docker")
|
||||
if !ok {
|
||||
log.Error("[InstallDockerBastion] - start docker service error ! %s", resultLog)
|
||||
return
|
||||
}
|
||||
|
||||
log.Info("Docker installed successfully from local file!")
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user