Skip to content

Commit

Permalink
重启前置命令优化
Browse files Browse the repository at this point in the history
  • Loading branch information
hale.huo committed May 8, 2021
1 parent af93076 commit 6e7c989
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/exec/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os/exec"
"path"
"strings"

"github.com/jinzhu/gorm"
"github.com/yuedun/zhuque/db"
Expand Down Expand Up @@ -240,8 +241,14 @@ func (u *execService) PostDeploy(deployConfig project.DeployConfig) ([]byte, err
for _, host := range deployConfig.Host {
go func(host string, ch chan []byte) {
// ssh user@remoteNode "cd /home ; ls"
// 用户名,IP,项目目录,前置命令, 命令
ssh := fmt.Sprintf("ssh %s@%s \"cd %s; %s; %s\"", deployConfig.User, host, deployConfig.Path, deployConfig.PreDeploy, deployConfig.PostDeploy)
// 用户名,IP,项目目录, 命令
ssh := fmt.Sprintf("ssh %s@%s \"cd %s; %s\"", deployConfig.User, host, deployConfig.Path, deployConfig.PostDeploy)
if deployConfig.PreDeploy != "" {
// 用户名,IP,项目目录,前置命令, 命令
po := strings.Index(deployConfig.PreDeploy, ";")
preDeploy := deployConfig.PreDeploy[:po]
ssh = fmt.Sprintf("ssh %s@%s \"cd %s; %s; %s\"", deployConfig.User, host, deployConfig.Path, preDeploy, deployConfig.PostDeploy)
}
cmdput, err := u.CmdSync(ssh)
if err != nil {
log.Println("postDeploy过程 远程命令执行失败:", err)
Expand Down
7 changes: 7 additions & 0 deletions tests/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func TestFile(t *testing.T) {
}
}

func TestSubstr(t *testing.T) {
str := "删掉了改好aaa中文;b中文二bb;"
po := strings.LastIndexAny(str, ";")
ss := str[:po]
t.Log(po, ss)
}

func TestChan(t *testing.T) {
ch := make(chan []byte, 3)
// errch := make(chan error, 3)
Expand Down

0 comments on commit 6e7c989

Please sign in to comment.