mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
🧐 预置升级任务,Agent 可禁止自动升级
This commit is contained in:
parent
4249fa82d7
commit
18483c0cb1
@ -38,9 +38,9 @@ _\* 使用 WatchTower 可以自动更新面板,Windows 终端可以使用 nssm
|
||||
|
||||
### 特殊技能
|
||||
|
||||
编辑 `/etc/systemd/system/nezha-agent.service`,在 `ExecStart=` 这一行的末尾加上
|
||||
通过执行 `./nezha-agent --help` 查看支持的参数,如果你使用一键脚本,可以编辑 `/etc/systemd/system/nezha-agent.service`,在 `ExecStart=` 这一行的末尾加上
|
||||
|
||||
- `--skip-conn` 不监控连接数,机场/连接密集型机器推荐设置,不然比较占CPU([shirou/gopsutil/issues#220](https://github.com/shirou/gopsutil/issues/220))
|
||||
- `--skip-conn` 不监控连接数,机场/连接密集型机器推荐设置,不然比较占 CPU([shirou/gopsutil/issues#220](https://github.com/shirou/gopsutil/issues/220))
|
||||
- `--disable-auto-update` 禁止 Agent 自动更新
|
||||
|
||||
## 功能说明
|
||||
|
@ -97,7 +97,13 @@ func run() {
|
||||
if _, err := semver.Parse(version); err == nil && !agentConf.DisableAutoUpdate {
|
||||
go func() {
|
||||
for range updateCh {
|
||||
go doSelfUpdate()
|
||||
go func() {
|
||||
defer func() {
|
||||
time.Sleep(time.Minute * 20)
|
||||
updateCh <- struct{}{}
|
||||
}()
|
||||
doSelfUpdate()
|
||||
}()
|
||||
}
|
||||
}()
|
||||
updateCh <- struct{}{}
|
||||
@ -186,6 +192,8 @@ func doTask(task *pb.Task) {
|
||||
handleTcpPingTask(task, &result)
|
||||
case model.TaskTypeCommand:
|
||||
handleCommandTask(task, &result)
|
||||
case model.TaskTypeUpgrade:
|
||||
handleUpgradeTask(task, &result)
|
||||
default:
|
||||
println("不支持的任务:", task)
|
||||
}
|
||||
@ -217,10 +225,6 @@ func reportState() {
|
||||
}
|
||||
|
||||
func doSelfUpdate() {
|
||||
defer func() {
|
||||
time.Sleep(time.Minute * 20)
|
||||
updateCh <- struct{}{}
|
||||
}()
|
||||
v := semver.MustParse(version)
|
||||
println("检查更新:", v)
|
||||
latest, err := selfupdate.UpdateSelf(v, "naiba/nezha")
|
||||
@ -233,6 +237,10 @@ func doSelfUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
func handleUpgradeTask(task *pb.Task, result *pb.TaskResult) {
|
||||
doSelfUpdate()
|
||||
}
|
||||
|
||||
func handleTcpPingTask(task *pb.Task, result *pb.TaskResult) {
|
||||
start := time.Now()
|
||||
conn, err := net.DialTimeout("tcp", task.GetData(), time.Second*10)
|
||||
|
@ -16,6 +16,7 @@ const (
|
||||
TaskTypeTCPPing
|
||||
TaskTypeCommand
|
||||
TaskTypeTerminal
|
||||
TaskTypeUpgrade
|
||||
)
|
||||
|
||||
type TerminalTask struct {
|
||||
|
Loading…
Reference in New Issue
Block a user