Esempio n. 1
0
func notifyReload() {
	pid_b, err := utils.ReadFile(PID_FILE)
	if err != nil {
		log.Fatalln("Error reading the file of this process id:", err)
	}
	pid_s := string(pid_b)

	log.Debug("This process id is ", pid_s)
	if strings.TrimSpace(pid_s) == "" {
		log.Fatalln("The file of this process id is empty.")
	}

	pid, err := strconv.Atoi(pid_s)
	if err != nil {
		log.Fatalf("String to int error: %s", err)
	}

	_, err = utils.ExecCommand(false, "kill", "-HUP", pid_s)
	if err != nil {
		log.Fatalf("Execute commmand <kill -HUP %s> error: %s", pid_s, err)
	}

	err = syscall.Kill(pid, syscall.SYS_READ)
	if err != nil {
		log.Fatalf("Kill signal send failed. Pid: %s, error: %s", pid_s, err)
	} else {
		log.Info("Configuration file is reloading...")
	}
}
Esempio n. 2
0
func (tm *TaskManager) updateUnits(unitCfg *config.UnitConfig, taskCfg *config.TaskConfig) error {

	id := fullId(taskCfg, unitCfg.Identity)
	log.Info("fullId = ", id)

	newUnit, err := units.NewUnit(unitCfg, taskCfg)
	if err != nil {
		return err
	}

	tm.m.Lock()
	defer tm.m.Unlock()

	if !tm.running {
		return nil
	}

	oldUnit, ok := tm.units[id]
	if ok {
		isMatch := (oldUnit.EqualTo(newUnit))
		log.Debug("is match = ", isMatch)
		if !isMatch {
			go newUnit.Start(tm.publisher.Queue)
			oldUnit.Stop()
			// delete(tm.units, id)
		}
	} else {
		go newUnit.Start(tm.publisher.Queue)
		tm.units[id] = newUnit
	}
	log.Info("units = ", tm.units)

	return nil
}
Esempio n. 3
0
func (tm *TaskManager) handleUnitUpdates(taskCfg *config.TaskConfig, ch <-chan *config.UnitConfig) {
	for unitCfg := range ch {
		//		log.Debugf("Received potential update for unit config %s", unitCfg.Identity)
		err := tm.updateUnits(unitCfg, taskCfg)
		if err != nil {
			log.Errorf("Error updating units: %s", err)
		}
	}
	log.Debug("handleUnitUpdates finished.")
}
Esempio n. 4
0
func (this *PublisherType) publishFromQueue() {
	for {
		select {
		case metric := <-this.Queue:
			this.publishMetric(metric)
		case <-this.publistStop:
			log.Debug("Done: This is publishFromQueue goroutine.")
			return
		}
	}
	/*
		for metric := range this.Queue {
			this.publishMetric(metric)
		}
	*/
}
Esempio n. 5
0
func (tm *TaskManager) removeUnits(f func(string) bool) {
	if f == nil {
		f = func(string) bool { return true }
	}

	log.Debug("length of tm.units is ", len(tm.units))

	var wg sync.WaitGroup
	for id, unit := range tm.units {
		if !f(id) {
			continue
		}
		wg.Add(1)
		go func(u units.Unit) {
			u.Stop()
			wg.Done()
		}(unit)
		delete(tm.units, id)
	}
	wg.Wait()
}