Skip to content

Commit 3ae18fd

Browse files
author
bajins
committed
add log;添加执行脚本为绝对路径
1 parent 627edfc commit 3ae18fd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"encoding/json"
55
"io/ioutil"
6+
"log"
67
)
78

89
var (
@@ -22,6 +23,7 @@ func LoadConfig() error {
2223
return err
2324
}
2425
json.Unmarshal(result, &config)
26+
log.Println("当前加载的配置:", config)
2527
return nil
2628
}
2729

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module webhook-go
22

33
go 1.13
4+
5+
require github.com/mitchellh/gox v1.0.1 // indirect

task.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package main
22

33
import (
44
"fmt"
5+
"log"
56
"os/exec"
7+
"path/filepath"
68
"webhook-go/utils"
79
)
810

@@ -33,11 +35,18 @@ func startTask(task *TaskQueue) {
3335
commands := config[task.Id].Commands
3436
running = true
3537
for _, v := range commands {
36-
_, err := exec.Command("/bin/sh", v).Output()
38+
filePath, err := filepath.Abs(v)
39+
if err != nil {
40+
utils.Log2file(fmt.Sprintf("部署失败:%s", err), GetLogName(task.Id))
41+
return
42+
}
43+
out, err := exec.Command("/bin/sh", filePath).Output()
44+
log.Println(filePath, "执行结果:", out)
3745
if err == nil {
38-
utils.Log2file(fmt.Sprintf("部署成功:%s", v), GetLogName(task.Id))
46+
utils.Log2file(fmt.Sprintf("部署成功:%s", filePath), GetLogName(task.Id))
3947
} else {
40-
utils.Log2file(fmt.Sprintf("部署失败:%s %s", v, err), GetLogName(task.Id))
48+
log.Fatal(filePath, "执行错误:", err)
49+
utils.Log2file(fmt.Sprintf("部署失败:%s %s", filePath, err), GetLogName(task.Id))
4150
}
4251
}
4352
queue = queue[:0]

0 commit comments

Comments
 (0)