From da6a2f8709db72bbcfd030fd2a8e94450a19cf97 Mon Sep 17 00:00:00 2001 From: fanux Date: Fri, 18 Oct 2019 14:12:24 +0800 Subject: [PATCH] fix sendpackage and cmd with workdir --- docs/v3.0.md | 2 ++ install/install.go | 8 +++++--- install/utils.go | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/docs/v3.0.md b/docs/v3.0.md index 54abac41e..0e95c4b6f 100644 --- a/docs/v3.0.md +++ b/docs/v3.0.md @@ -196,6 +196,8 @@ mkdir dashboard && cd dashboard ```cassandraql echo "LOAD docker load -i image.tar" >> config echo "APPLY kubectl apply -f dashboard.yaml" >> config +echo "DELETE kubectl delete -f dashboard.yaml" >> config +echo "REMOVE sleep 10 && docker rmi -f dashboard:latest" >> config ``` 3. 下载yaml文件与保存镜像 diff --git a/install/install.go b/install/install.go index fab26149b..05bd2e2b0 100644 --- a/install/install.go +++ b/install/install.go @@ -159,16 +159,17 @@ type RunOnEveryNodes struct { func (r *RunOnEveryNodes) Run(config SealConfig, url, pkgName string) { var wg sync.WaitGroup tarCmd := fmt.Sprintf("tar xvf %s.tar", pkgName) + workspace := fmt.Sprintf("/root/%s", pkgName) nodes := append(config.Masters, config.Nodes...) - SendPackage(url, nodes, pkgName) + FetchPackage(url, nodes, workspace) for _, node := range nodes { wg.Add(1) go func(node string) { defer wg.Done() Cmd(node, tarCmd) for _, cmd := range r.Cmd { - CmdWorkSpace(node, cmd.Cmd, fmt.Sprintf("/root/%s", pkgName)) + CmdWorkSpace(node, cmd.Cmd, workspace) } }(node) } @@ -181,9 +182,10 @@ type RunOnMaster struct { } func (r *RunOnMaster) Run(config SealConfig, url, pkgName string) { + workspace := fmt.Sprintf("/root/%s", pkgName) SendPackage(url, []string{config.Masters[0]}, pkgName) for _, cmd := range r.Cmd { - CmdWorkSpace(config.Masters[0], cmd.Cmd,fmt.Sprintf("/root/%s", pkgName)) + CmdWorkSpace(config.Masters[0], cmd.Cmd, workspace) } } diff --git a/install/utils.go b/install/utils.go index fd792dba9..d4bc4c871 100644 --- a/install/utils.go +++ b/install/utils.go @@ -335,3 +335,44 @@ func SendPackage(url string, hosts []string, packName string) { } wm.Wait() } + +// FetchPackage if url exist wget it, or scp the local package to hosts +// dst is the remote offline path like /root +func FetchPackage(url string, hosts []string, dst string) { + pkg := path.Base(url) + fullDst := fmt.Sprintf("%s/%s", dst, pkg) + mkdstdir := fmt.Sprintf("mkdir -p %s || true", dst) + + //only http + isHttp := strings.HasPrefix(url, "http") + wgetCommand := "" + if isHttp { + wgetParam := "" + if strings.HasPrefix(url, "https") { + wgetParam = "--no-check-certificate" + } + wgetCommand = fmt.Sprintf(" wget %s ", wgetParam) + } + remoteCmd := fmt.Sprintf("cd %s && %s %s", dst, wgetCommand, url) + + var wm sync.WaitGroup + for _, host := range hosts { + wm.Add(1) + go func(host string) { + defer wm.Done() + logger.Debug("[%s]please wait for copy offline package", host) + Cmd(host, mkdstdir) + if RemoteFilExist(host, fullDst) { + logger.Warn("[%s]SendPackage: [%s] file is exist", host, fullDst) + } else { + if isHttp { + go WatchFileSize(host, fullDst, GetFileSize(url)) + Cmd(host, remoteCmd) + } else { + Copy(host, url, fullDst) + } + } + }(host) + } + wm.Wait() +}