Skip to content

Commit

Permalink
♻️ register when upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Nov 30, 2020
1 parent a0a3ee3 commit 7ce1f53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 11 additions & 8 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
server string
clientSecret string
debug bool
version string = "0.1.4"
version string

rootCmd = &cobra.Command{
Use: "nezha-agent",
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 7ce1f53

Please sign in to comment.