[dashboard 0.4.1 & agent 0.3.4] 🚸 添加计划任务文案、计划任务超时
This commit is contained in:
parent
70e5336fc1
commit
67230ee4b8
@ -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。
|
系统状态监控报警、API(SSL证书变更、即将到期、到期)/TCP端口存活/PING 监控、计划任务(可以定时在Agent上执行命令,备份、重启、What ever you want)、极省资源,64M 服务器也能装 agent。
|
||||||
|
|
||||||
|
@ -232,19 +232,32 @@ func doTask(task *pb.Task) {
|
|||||||
case model.TaskTypeCommand:
|
case model.TaskTypeCommand:
|
||||||
startedAt := time.Now()
|
startedAt := time.Now()
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
|
var resChan chan string
|
||||||
|
var errChan chan string
|
||||||
|
timeout := time.NewTimer(time.Minute * 30)
|
||||||
if utils.IsWindows() {
|
if utils.IsWindows() {
|
||||||
cmd = exec.Command("cmd", "/c", task.GetData())
|
cmd = exec.Command("cmd", "/c", task.GetData())
|
||||||
} else {
|
} else {
|
||||||
cmd = exec.Command("sh", "-c", task.GetData())
|
cmd = exec.Command("sh", "-c", task.GetData())
|
||||||
}
|
}
|
||||||
|
go func(resChan, errChan chan string) {
|
||||||
output, err := cmd.Output()
|
output, err := cmd.Output()
|
||||||
result.Delay = float32(time.Now().Sub(startedAt).Seconds())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Data = fmt.Sprintf("%s\n%s", string(output), err.Error())
|
errChan <- fmt.Sprintf("%s\n%s", string(output), err.Error())
|
||||||
} else {
|
return
|
||||||
result.Data = string(output)
|
|
||||||
result.Successful = true
|
|
||||||
}
|
}
|
||||||
|
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:
|
default:
|
||||||
log.Printf("Unknown action: %v", task)
|
log.Printf("Unknown action: %v", task)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
计划的格式为:<code>* * * * *</code> 分 时 天 月 星期,详情见 <a
|
计划的格式为:<code>* * * * *</code> 分 时 天 月 星期,详情见 <a
|
||||||
href="https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format"
|
href="https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format"
|
||||||
target="_blank">计划表达式格式</a><br>
|
target="_blank">计划表达式格式</a><br>
|
||||||
命令:就像写 shell/bat 脚本一样,但是不推荐换行,多个命令使用 `&&`/`&` 连接,如果遇到 xxx 命令找不到,可能是 <code>PATH</code> 环境变量的问题,`Linux` 主机在命令开头加入
|
命令:就像写 shell/bat 脚本一样,但是不推荐换行,多个命令使用 <code>&&</code>/<code>&</code> 连接,如果遇到 xxx 命令找不到,可能是 <code>PATH</code> 环境变量的问题,<code>Linux</code> 主机在命令开头加入
|
||||||
<code>source ~/.bashrc</code>或者使用绝对路径执行。
|
<code>source ~/.bashrc</code>或者使用绝对路径执行。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
pb "github.com/naiba/nezha/proto"
|
pb "github.com/naiba/nezha/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "v0.4.0" // !!记得修改 README 重的 badge 版本!!
|
var Version = "v0.4.1" // !!记得修改 README 重的 badge 版本!!
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SnapshotDelay = 3
|
SnapshotDelay = 3
|
||||||
|
Loading…
Reference in New Issue
Block a user