fix sendpackage and cmd with workdir

This commit is contained in:
fanux
2019-10-18 14:12:24 +08:00
parent f84f80dc95
commit da6a2f8709
3 changed files with 48 additions and 3 deletions
+2
View File
@@ -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文件与保存镜像
+5 -3
View File
@@ -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)
}
}
+41
View File
@@ -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()
}