Commit a55ff762 authored by 957dd's avatar 957dd

加入了下载后自己重启

parent a779d0e4
No preview for this file type
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -189,18 +189,35 @@ func main() {
if err != nil {
fmt.Printf("写入版本号配置文件出错: %v\n", err)
}
//对文件进行授权
permiss()
time.Sleep(2 * time.Second)
startCarStartService()
//对文件进行授权
time.Sleep(3 * time.Second)
// 添加执行重启命令
fmt.Println("准备重启系统...")
err := execReboot()
if err != nil {
fmt.Printf("执行重启命令失败: %v\n", err)
continue
}
} else {
fmt.Printf("MD5 检验失败,期望的 MD5 值: %s,实际的 MD5 值: %s\n", result.Data.MD5, fileMD5)
os.Remove(tempDownloadPath)
rollbackToBackup(downloadPath, backupDir, lastVersion)
startCarStartService()
}
} else {
fmt.Println("版本号相同,无需下载")
}
//对文件进行授权
permiss()
// 轮询间隔,这里设置为 30 分钟
time.Sleep(30 * time.Minute)
}
......@@ -339,3 +356,14 @@ func permiss() error {
// 命令执行成功,返回 nil 表示没有错误
return nil
}
// 执行重启命令
func execReboot() error {
cmd := exec.Command("sudo", "reboot")
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("执行重启失败: %v, 输出: %s", err, string(output))
}
fmt.Println("重启命令已执行")
return nil
}
\ No newline at end of file
1.2.3
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment