From 7ce1f535f52a6219209f9a2e3d2af0d4096b7eb1 Mon Sep 17 00:00:00 2001 From: naiba Date: Mon, 30 Nov 2020 14:24:00 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20register=20when=20upgrade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/agent/main.go | 19 +++++++++++-------- script/install.sh | 1 - 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 2541bc6..1c17959 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -25,7 +25,7 @@ var ( server string clientSecret string debug bool - version string = "0.1.4" + version string rootCmd = &cobra.Command{ Use: "nezha-agent", @@ -39,6 +39,15 @@ var ( } ) +var ( + endReport time.Time + reporting bool + client pb.NezhaServiceClient + ctx = context.Background() + delayWhenError = time.Second * 10 + updateCh = make(chan struct{}, 0) +) + func doSelfUpdate() { defer func() { time.Sleep(time.Minute * 20) @@ -55,6 +64,7 @@ func doSelfUpdate() { // latest version is the same as current version. It means current binary is up to date. log.Println("Current binary is the latest version", version) } else { + client.Register(ctx, monitor.GetHost().PB()) log.Println("Successfully updated to version", latest.Version) log.Println("Release note:\n", latest.ReleaseNotes) } @@ -74,13 +84,6 @@ func main() { } } -var endReport time.Time -var reporting bool -var client pb.NezhaServiceClient -var ctx = context.Background() -var delayWhenError = time.Second * 10 -var updateCh = make(chan struct{}, 0) - func run(cmd *cobra.Command, args []string) { dao.Conf = &model.Config{ Debug: debug, diff --git a/script/install.sh b/script/install.sh index 38a6c9c..5008363 100755 --- a/script/install.sh +++ b/script/install.sh @@ -190,7 +190,6 @@ install_agent() { modify_agent_config() { echo -e "> 修改Agent配置" - cd $NZ_AGENT_PATH curl -L https://raw.githubusercontent.com/naiba/nezha/master/script/nezha-agent.service -o $NZ_AGENT_SERVICE >/dev/null 2>&1 if [[ $? != 0 ]]; then echo -e "${red}文件下载失败,请检查本机能否连接 raw.githubusercontent.com${plain}"