Exemple #1
0
func (c *Controller) Update() (string, error) {

	if c.SessRestricted != 0 || !c.NodeAdmin {
		return "", utils.ErrInfo(errors.New("Permission denied"))
	}

	ver, _, err := utils.GetUpdVerAndUrl(consts.UPD_AND_VER_URL)
	if err != nil {
		return "", utils.ErrInfo(err)
	}
	if len(ver) > 0 {
		newVersion := strings.Replace(c.Lang["new_version"], "[ver]", ver, -1)
		return utils.JsonAnswer(newVersion, "success").String(), nil
	}
	return "", nil
}
Exemple #2
0
func AutoUpdate(chBreaker chan bool, chAnswer chan string) {
	defer func() {
		if r := recover(); r != nil {
			log.Error("daemon Recovered", r)
			panic(r)
		}
	}()

	GoroutineName := "AutoUpdate"
	d := new(daemon)
	d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
	if d.DCDB == nil {
		return
	}
	d.goRoutineName = GoroutineName
	d.chAnswer = chAnswer
	d.chBreaker = chBreaker
	d.sleepTime = 3600
	if !d.CheckInstall(chBreaker, chAnswer, GoroutineName) {
		return
	}
	d.DCDB = DbConnect(chBreaker, chAnswer, GoroutineName)
	if d.DCDB == nil {
		return
	}

BEGIN:
	for {
		log.Info(GoroutineName)
		MonitorDaemonCh <- []string{GoroutineName, utils.Int64ToStr(utils.Time())}

		// проверим, не нужно ли нам выйти из цикла
		if CheckDaemonsRestart(chBreaker, chAnswer, GoroutineName) {
			break BEGIN
		}

		config, err := d.GetNodeConfig()
		if err != nil {
			if d.dPrintSleep(err, d.sleepTime) {
				break BEGIN
			}
			continue BEGIN
		}

		if config["auto_update"] == "1" {
			updTime, _ := ioutil.ReadFile(*utils.Dir + "/auto_update")
			log.Debug("updTime %v / ", utils.BytesToInt64(updTime))
			//fmt.Println(utils.BytesToInt64(updTime))
			if utils.Time()-utils.BytesToInt64(updTime) < int64(d.sleepTime) {
				log.Debug("sleepTime")
				//fmt.Println("sleepTime")
				if d.dSleep(d.sleepTime) {
					break BEGIN
				}
				continue BEGIN
			}
			_, url, err := utils.GetUpdVerAndUrl(config["auto_update_url"])
			//fmt.Println("url", url)
			if err != nil {
				if d.dPrintSleep(err, d.sleepTime) {
					break BEGIN
				}
				continue BEGIN
			}
			if len(url) > 0 {
				f, _ := os.OpenFile(*utils.Dir+"/auto_update", os.O_WRONLY|os.O_CREATE, 0600)
				f.WriteString(utils.Int64ToStr(utils.Time()))
				f.Close()
				err = utils.DcoinUpd(url)
				if err != nil {
					if d.dPrintSleep(err, d.sleepTime) {
						break BEGIN
					}
					continue BEGIN
				}
			}
		}

		if d.dSleep(d.sleepTime) {
			break BEGIN
		}
	}
	log.Debug("break BEGIN %v", GoroutineName)
}