🐛 fix auto update
This commit is contained in:
		
							parent
							
								
									e0a26267bd
								
							
						
					
					
						commit
						fe5cfeb12a
					
				@ -25,7 +25,7 @@ var (
 | 
				
			|||||||
	server       string
 | 
						server       string
 | 
				
			||||||
	clientSecret string
 | 
						clientSecret string
 | 
				
			||||||
	debug        bool
 | 
						debug        bool
 | 
				
			||||||
	version      string
 | 
						version      string = "0.1.4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rootCmd = &cobra.Command{
 | 
						rootCmd = &cobra.Command{
 | 
				
			||||||
		Use:   "nezha-agent",
 | 
							Use:   "nezha-agent",
 | 
				
			||||||
@ -41,10 +41,11 @@ var (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func doSelfUpdate() {
 | 
					func doSelfUpdate() {
 | 
				
			||||||
	defer func() {
 | 
						defer func() {
 | 
				
			||||||
		time.Sleep(time.Minute * 20)
 | 
							time.Sleep(time.Second * 3)
 | 
				
			||||||
		updateCh <- struct{}{}
 | 
							updateCh <- struct{}{}
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
	v := semver.MustParse(version)
 | 
						v := semver.MustParse(version)
 | 
				
			||||||
 | 
						log.Println("check update", v)
 | 
				
			||||||
	latest, err := selfupdate.UpdateSelf(v, "naiba/nezha")
 | 
						latest, err := selfupdate.UpdateSelf(v, "naiba/nezha")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Println("Binary update failed:", err)
 | 
							log.Println("Binary update failed:", err)
 | 
				
			||||||
@ -94,8 +95,7 @@ func run(cmd *cobra.Command, args []string) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		for range updateCh {
 | 
							for range updateCh {
 | 
				
			||||||
			log.Println("check update", version)
 | 
								go doSelfUpdate()
 | 
				
			||||||
			doSelfUpdate()
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user