diff --git a/node/icecast.go b/node/icecast.go index 50ee1644291a416dcd2c7c2abd43b96443a3fa8a..54090a4e579b9682c27e52f51f0d4e77dc96e545 100644 --- a/node/icecast.go +++ b/node/icecast.go @@ -110,7 +110,7 @@ func (ic *IcecastController) statusUpdater() { ic.status = status icecastOk.Set(1) } else { - log.Printf("bad status from iceast: %v", err) + log.Printf("error checking iceast status: %v", err) ic.status = downStatus icecastOk.Set(0) } diff --git a/node/node.go b/node/node.go index 252225431e79c8370781a70ef183129f2550a813..33db652d614d151614b55dc7f95ddf814a72d8b3 100644 --- a/node/node.go +++ b/node/node.go @@ -104,6 +104,17 @@ func (w *ConfigSyncer) setIndex(index uint64) { configIndex.Set(int64(index)) } +func (w *ConfigSyncer) updateConfigWithResponse(index uint64, key, value string) { + mountName := keyToMount(key) + log.Printf("updating mount %s [@%d]: %s", mountName, index, value) + var m autoradio.Mount + if err := json.NewDecoder(strings.NewReader(value)).Decode(&m); err != nil { + log.Printf("corrupted data: %s: %s", value, err) + } else { + w.config.setMount(&m) + } +} + func (w *ConfigSyncer) syncer(ch chan *etcd.Response) { for { select { @@ -124,7 +135,7 @@ func (w *ConfigSyncer) syncer(ch chan *etcd.Response) { log.Printf("deleted mount %s", mountName) w.config.delMount(mountName) } else if response.Action == "set" || response.Action == "create" || response.Action == "update" { - w.updateConfigWithResponse(response.Node.Key, response.Node.Value) + w.updateConfigWithResponse(response.EtcdIndex, response.Node.Key, response.Node.Value) } else { continue } @@ -138,17 +149,6 @@ func (w *ConfigSyncer) syncer(ch chan *etcd.Response) { } } -func (w *ConfigSyncer) updateConfigWithResponse(key, value string) { - mountName := keyToMount(key) - log.Printf("updating mount %s: %s", mountName, value) - var m autoradio.Mount - if err := json.NewDecoder(strings.NewReader(value)).Decode(&m); err != nil { - log.Printf("corrupted data: %s: %s", value, err) - } else { - w.config.setMount(&m) - } -} - // Load full configuration from etcd. This will trigger the update channel. func (w *ConfigSyncer) loadFullConfig() { for { @@ -156,8 +156,9 @@ func (w *ConfigSyncer) loadFullConfig() { if err == nil && response.Node != nil && response.Node.Dir { // Directly update the configuration. for _, n := range response.Node.Nodes { - w.updateConfigWithResponse(n.Key, n.Value) + w.updateConfigWithResponse(response.EtcdIndex, n.Key, n.Value) } + log.Printf("got configuration at index %d", response.EtcdIndex) w.setIndex(response.EtcdIndex) break } @@ -172,7 +173,6 @@ func (w *ConfigSyncer) loadFullConfig() { } // Update the icecast daemon now that we have a full config. - log.Printf("triggering initial reload") trigger(w.upch) } @@ -181,13 +181,12 @@ func (w *ConfigSyncer) loadFullConfig() { // in-memory configuration has already been fully synchronized. func (w *ConfigSyncer) Start() { // Run until the first successful Get(). - log.Printf("attempting to retrieve initial config") + log.Printf("retrieving initial config") w.loadFullConfig() // Main watch loop. Remember that etcd.Watch() will close the // receiver channel when it returns, so we need to start a new // syncer every time. - log.Printf("starting config syncer") go func() { for { ch := make(chan *etcd.Response)