diff --git a/README.md b/README.md index 5f0174f..cfca507 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 哪吒面板 -![dashboard](https://img.shields.io/badge/管理面板-v0.4.0-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github) +![dashboard](https://img.shields.io/badge/管理面板-v0.4.1-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github) 系统状态监控报警、API(SSL证书变更、即将到期、到期)/TCP端口存活/PING 监控、计划任务(可以定时在Agent上执行命令,备份、重启、What ever you want)、极省资源,64M 服务器也能装 agent。 diff --git a/cmd/agent/main.go b/cmd/agent/main.go index ed2f89c..76515a9 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -232,19 +232,32 @@ func doTask(task *pb.Task) { case model.TaskTypeCommand: startedAt := time.Now() var cmd *exec.Cmd + var resChan chan string + var errChan chan string + timeout := time.NewTimer(time.Minute * 30) if utils.IsWindows() { cmd = exec.Command("cmd", "/c", task.GetData()) } else { cmd = exec.Command("sh", "-c", task.GetData()) } - output, err := cmd.Output() - result.Delay = float32(time.Now().Sub(startedAt).Seconds()) - if err != nil { - result.Data = fmt.Sprintf("%s\n%s", string(output), err.Error()) - } else { - result.Data = string(output) + go func(resChan, errChan chan string) { + output, err := cmd.Output() + if err != nil { + errChan <- fmt.Sprintf("%s\n%s", string(output), err.Error()) + return + } + resChan <- string(output) + }(resChan, errChan) + select { + case <-timeout.C: + result.Data = "任务执行超时(30分钟)" + case output := <-resChan: + result.Data = output result.Successful = true + case errString := <-errChan: + result.Data = errString } + result.Delay = float32(time.Now().Sub(startedAt).Seconds()) default: log.Printf("Unknown action: %v", task) } diff --git a/resource/template/component/cron.html b/resource/template/component/cron.html index 2c235ae..2f15311 100644 --- a/resource/template/component/cron.html +++ b/resource/template/component/cron.html @@ -37,7 +37,7 @@ 计划的格式为:* * * * * 分 时 天 月 星期,详情见 计划表达式格式
- 命令:就像写 shell/bat 脚本一样,但是不推荐换行,多个命令使用 `&&`/`&` 连接,如果遇到 xxx 命令找不到,可能是 PATH 环境变量的问题,`Linux` 主机在命令开头加入 + 命令:就像写 shell/bat 脚本一样,但是不推荐换行,多个命令使用 &&/& 连接,如果遇到 xxx 命令找不到,可能是 PATH 环境变量的问题,Linux 主机在命令开头加入 source ~/.bashrc或者使用绝对路径执行。

diff --git a/service/dao/dao.go b/service/dao/dao.go index 8cd0cdd..fe9127b 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -13,7 +13,7 @@ import ( pb "github.com/naiba/nezha/proto" ) -var Version = "v0.4.0" // !!记得修改 README 重的 badge 版本!! +var Version = "v0.4.1" // !!记得修改 README 重的 badge 版本!! const ( SnapshotDelay = 3