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

improve debugging for the icecast controller

parent 7e551437
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ package node
import (
"encoding/xml"
"errors"
"fmt"
"io"
"log"
"net/http"
......@@ -16,7 +17,9 @@ import (
)
var (
statusPageUrl = "http://localhost:8000/status-autoradio.xsl"
statusPage = "/status-autoradio.xsl"
icecastConfigFile = "/etc/icecast2/icecast.xml"
icecastReloadCmd = "/usr/sbin/service icecast2 reload || /usr/sbin/service icecast2 start"
icecastOk = instrumentation.NewGauge("icecast.ok")
)
......@@ -48,31 +51,26 @@ type IcecastStatus struct {
}
type IcecastController struct {
PublicIp string
ConfigFile string
InitScript string
config *icecastConfig
status *IcecastStatus
stop chan bool
config *icecastConfig
status *IcecastStatus
stop chan bool
}
func NewIcecastController(publicIp string, stop chan bool) *IcecastController {
return &IcecastController{
PublicIp: publicIp,
ConfigFile: "/etc/icecast2/icecast.xml",
InitScript: "/etc/init.d/icecast2",
config: newIcecastConfig(publicIp),
status: &IcecastStatus{},
stop: make(chan bool, 1),
config: newIcecastConfig(publicIp),
status: &IcecastStatus{},
stop: make(chan bool, 1),
}
}
// Reload the icecast daemon. Redirects output to our standard error
// for debugging purposes.
func (ic *IcecastController) reload() error {
err := exec.Command(ic.InitScript, "reload").Run()
if err != nil {
err = exec.Command(ic.InitScript, "start").Run()
}
return err
cmd := exec.Command("/bin/sh", "-c", icecastReloadCmd)
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
return cmd.Run()
}
// Update reloads the Icecast daemon with a new configuration.
......@@ -81,7 +79,7 @@ func (ic *IcecastController) Update(conf *ClusterConfig, isMaster bool, masterAd
return errors.New("unknown system state")
}
tmpf := ic.ConfigFile + ".tmp"
tmpf := icecastConfigFile + ".tmp"
defer os.Remove(tmpf)
ic.config.Update(conf, isMaster, masterAddr)
......@@ -89,7 +87,7 @@ func (ic *IcecastController) Update(conf *ClusterConfig, isMaster bool, masterAd
return err
}
if err := os.Rename(tmpf, ic.ConfigFile); err != nil {
if err := os.Rename(tmpf, icecastConfigFile); err != nil {
return err
}
......@@ -121,7 +119,7 @@ func (ic *IcecastController) statusUpdater() {
}
func (ic *IcecastController) fetchStatus() (*IcecastStatus, error) {
resp, err := http.Get(statusPageUrl)
resp, err := http.Get(fmt.Sprintf("http://localhost:%d%s", autoradio.IcecastPort, statusPage))
if err != nil {
return nil, err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment