Skip to content
Snippets Groups Projects
Commit 7e551437 authored by ale's avatar ale
Browse files

minor logging fixes

parent 353e1579
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment