Example #1
0
File: master.go Project: banduk/apm
// InitMaster will start a master instance with configFile.
// It returns a Master instance.
func InitMaster(configFile string) *Master {
	watcher := watcher.InitWatcher()
	master := &Master{}
	master.Procs = make(map[string]*process.Proc)
	err := utils.SafeReadTomlFile(configFile, master)
	if err != nil {
		panic(err)
	}
	master.Watcher = watcher
	master.Revive()
	log.Infof("All procs revived...")
	go master.WatchProcs()
	go master.SaveProcs()
	go master.UpdateStatus()
	return master
}
Example #2
0
// InitMaster will start a master instance with configFile.
// It returns a Master instance.
func InitMaster(configFile string) *Master {
	watcher := watcher.InitWatcher()
	decodableMaster := &DecodableMaster{}
	decodableMaster.Procs = make(map[string]*process.Proc)

	err := utils.SafeReadTomlFile(configFile, decodableMaster)
	if err != nil {
		panic(err)
	}

	procs := make(map[string]process.ProcContainer)
	for k, v := range decodableMaster.Procs {
		procs[k] = v
	}
	// We need this hack because toml decoder doesn't decode to interfaces
	master := &Master{
		SysFolder: decodableMaster.SysFolder,
		PidFile:   decodableMaster.PidFile,
		OutFile:   decodableMaster.OutFile,
		ErrFile:   decodableMaster.ErrFile,
		Watcher:   decodableMaster.Watcher,
		Procs:     procs,
	}

	if master.SysFolder == "" {
		os.MkdirAll(path.Dir(configFile), 0777)
		master.SysFolder = path.Dir(configFile) + "/"
	}
	master.Watcher = watcher
	master.Revive()
	log.Infof("All procs revived...")
	go master.WatchProcs()
	go master.SaveProcsLoop()
	go master.UpdateStatus()
	return master
}