This commit is contained in:
2015-02-11 20:57:25 +07:00
parent 7f552e5c8a
commit d991f1abb5
6 changed files with 65 additions and 47 deletions
+30
View File
@@ -0,0 +1,30 @@
package core
import (
"github.com/localhots/yeast/chain"
"github.com/localhots/yeast/unit"
)
type (
App struct {
config *Config
chains *chain.Bank
}
)
func NewApp() *App {
a := &App{
config: &Config{},
}
a.config.Init()
ub := unit.NewBank(a.Conf().UnitsConfig)
a.chains = chain.NewBank(a.Conf().ChainsConfig, ub)
a.chains.Reload()
return a
}
func (a *App) Conf() Config {
return a.config.conf.Config().(Config)
}
+6 -13
View File
@@ -8,6 +8,7 @@ import (
type (
Config struct {
conf *confection.Manager
ChainsConfig string `json:"chains_config_path" attrs:"required" title:"Chains config path"`
UnitsConfig string `json:"units_config_path" attrs:"required" title:"Units config path"`
Python Python `json:"python" title:"Python"`
@@ -18,21 +19,13 @@ type (
}
)
var (
conf *confection.Manager
)
func Conf() Config {
return conf.Config().(Config)
func (c *Config) Init() {
c.conf = confection.New(*c, c.decoder)
go c.conf.StartServer()
c.conf.RequireConfig()
}
func InitConfig() {
conf = confection.New(Config{}, ConfigDecoder)
go conf.StartServer()
conf.RequireConfig()
}
func ConfigDecoder(b []byte) interface{} {
func (c *Config) decoder(b []byte) interface{} {
var newConf Config
if err := json.Unmarshal(b, &newConf); err != nil {
panic(err)
+5 -3
View File
@@ -8,7 +8,10 @@ import (
)
type (
Supervisor struct{}
Supervisor struct {
pythonBin string
pythonWrapper string
}
)
// XXX: We're about to spawn hundreds of Python processes
@@ -21,8 +24,7 @@ func (s *Supervisor) StartAll(units []string) {
func (s *Supervisor) Start(name string) {
fmt.Println("Starting unit: " + name)
conf := Conf().Python
cmd := exec.Command(conf.BinPath, conf.WrapperPath, name)
cmd := exec.Command(s.pythonBin, s.pythonWrapper, name)
cmd.Stdout = os.Stdout // Sorry
if err := cmd.Start(); err != nil {
fmt.Println("Failed to start unit: ", name)