Skip to content

Commit

Permalink
Better trace serf setup errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed May 27, 2015
1 parent 0d5f8e6 commit 4ce769b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dcron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (a *AgentCommand) readConfig(args []string) *Config {
viper.SetDefault("etcd_machines", cmdFlags.Lookup("etcd-machines").Value)
cmdFlags.String("profile", "lan", "timing profile to use (lan, wan, local)")
viper.SetDefault("profile", cmdFlags.Lookup("profile").Value)
cmdFlags.Bool("server", false, "start dcron server")
cmdFlags.Bool("server", true, "start dcron server")
viper.SetDefault("server", cmdFlags.Lookup("server").Value)

// cmdFlags.Var((*AppendSliceValue)(&configFiles), "config-file",
Expand All @@ -77,7 +77,7 @@ func (a *AgentCommand) readConfig(args []string) *Config {
HTTPAddr: viper.GetString("http_addr"),
Discover: viper.GetString("discover"),
EtcdMachines: viper.GetStringSlice("etcd_machines"),
Server: viper.GetBool("server"),
Server: true,
Profile: viper.GetString("profile"),
}

Expand Down Expand Up @@ -237,6 +237,7 @@ func (a *AgentCommand) setupSerf(config *Config) *serf.Serf {
// Create serf first
serf, err := serf.Create(serfConfig)
if err != nil {
a.Ui.Error(err.Error())
return nil
}

Expand All @@ -245,9 +246,12 @@ func (a *AgentCommand) setupSerf(config *Config) *serf.Serf {

func (a *AgentCommand) Run(args []string) int {
a.config = a.readConfig(args)
a.serf = a.setupSerf(a.config)
if a.serf = a.setupSerf(a.config); a.serf == nil {
log.Fatal("Can not setup serf")
}
a.etcd = NewEtcdClient(a.config.EtcdMachines)

log.Debug(a.config.Server)
if a.config.Server {
go func() {
a.ServeHTTP()
Expand All @@ -260,7 +264,7 @@ func (a *AgentCommand) Run(args []string) int {
}
sched.Start(jobs)
}
a.eventLoop()
a.serverEventLoop()
}

return 0
Expand Down Expand Up @@ -318,7 +322,7 @@ func (a *AgentCommand) isActiveMember(memberName string) bool {
}

// eventLoop listens to events from Serf and fans out to event handlers
func (a *AgentCommand) eventLoop() {
func (a *AgentCommand) serverEventLoop() {
serfShutdownCh := a.serf.ShutdownCh()
for {
select {
Expand Down

0 comments on commit 4ce769b

Please sign in to comment.