Start 启动升级
()
| 39 | |
| 40 | // Start 启动升级 |
| 41 | func (this *UpgradeManager) Start() { |
| 42 | // 必须放在文件解压之前读取可执行文件路径,防止解析之后,当前的可执行文件路径发生改变 |
| 43 | exe, err := os.Executable() |
| 44 | if err != nil { |
| 45 | remotelogs.Error("UPGRADE_MANAGER", "can not find current executable file name") |
| 46 | return |
| 47 | } |
| 48 | this.exe = exe |
| 49 | |
| 50 | // 测试环境下不更新 |
| 51 | if Tea.IsTesting() { |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | if this.isInstalling { |
| 56 | return |
| 57 | } |
| 58 | this.isInstalling = true |
| 59 | |
| 60 | remotelogs.Println("UPGRADE_MANAGER", "upgrading node ...") |
| 61 | err = this.install() |
| 62 | if err != nil { |
| 63 | remotelogs.Error("UPGRADE_MANAGER", "download failed: "+err.Error()) |
| 64 | |
| 65 | this.isInstalling = false |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | remotelogs.Println("UPGRADE_MANAGER", "upgrade successfully") |
| 70 | |
| 71 | goman.New(func() { |
| 72 | err = this.restart() |
| 73 | if err != nil { |
| 74 | remotelogs.Error("UPGRADE_MANAGER", err.Error()) |
| 75 | } |
| 76 | |
| 77 | this.isInstalling = false |
| 78 | }) |
| 79 | } |
| 80 | |
| 81 | // IsInstalling 检查是否正在安装 |
| 82 | func (this *UpgradeManager) IsInstalling() bool { |