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 ...@@ -3,6 +3,7 @@ package node
import ( import (
"encoding/xml" "encoding/xml"
"errors" "errors"
"fmt"
"io" "io"
"log" "log"
"net/http" "net/http"
...@@ -16,7 +17,9 @@ import ( ...@@ -16,7 +17,9 @@ import (
) )
var ( 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") icecastOk = instrumentation.NewGauge("icecast.ok")
) )
...@@ -48,9 +51,6 @@ type IcecastStatus struct { ...@@ -48,9 +51,6 @@ type IcecastStatus struct {
} }
type IcecastController struct { type IcecastController struct {
PublicIp string
ConfigFile string
InitScript string
config *icecastConfig config *icecastConfig
status *IcecastStatus status *IcecastStatus
stop chan bool stop chan bool
...@@ -58,21 +58,19 @@ type IcecastController struct { ...@@ -58,21 +58,19 @@ type IcecastController struct {
func NewIcecastController(publicIp string, stop chan bool) *IcecastController { func NewIcecastController(publicIp string, stop chan bool) *IcecastController {
return &IcecastController{ return &IcecastController{
PublicIp: publicIp,
ConfigFile: "/etc/icecast2/icecast.xml",
InitScript: "/etc/init.d/icecast2",
config: newIcecastConfig(publicIp), config: newIcecastConfig(publicIp),
status: &IcecastStatus{}, status: &IcecastStatus{},
stop: make(chan bool, 1), stop: make(chan bool, 1),
} }
} }
// Reload the icecast daemon. Redirects output to our standard error
// for debugging purposes.
func (ic *IcecastController) reload() error { func (ic *IcecastController) reload() error {
err := exec.Command(ic.InitScript, "reload").Run() cmd := exec.Command("/bin/sh", "-c", icecastReloadCmd)
if err != nil { cmd.Stdout = os.Stderr
err = exec.Command(ic.InitScript, "start").Run() cmd.Stderr = os.Stderr
} return cmd.Run()
return err
} }
// Update reloads the Icecast daemon with a new configuration. // Update reloads the Icecast daemon with a new configuration.
...@@ -81,7 +79,7 @@ func (ic *IcecastController) Update(conf *ClusterConfig, isMaster bool, masterAd ...@@ -81,7 +79,7 @@ func (ic *IcecastController) Update(conf *ClusterConfig, isMaster bool, masterAd
return errors.New("unknown system state") return errors.New("unknown system state")
} }
tmpf := ic.ConfigFile + ".tmp" tmpf := icecastConfigFile + ".tmp"
defer os.Remove(tmpf) defer os.Remove(tmpf)
ic.config.Update(conf, isMaster, masterAddr) ic.config.Update(conf, isMaster, masterAddr)
...@@ -89,7 +87,7 @@ func (ic *IcecastController) Update(conf *ClusterConfig, isMaster bool, masterAd ...@@ -89,7 +87,7 @@ func (ic *IcecastController) Update(conf *ClusterConfig, isMaster bool, masterAd
return err return err
} }
if err := os.Rename(tmpf, ic.ConfigFile); err != nil { if err := os.Rename(tmpf, icecastConfigFile); err != nil {
return err return err
} }
...@@ -121,7 +119,7 @@ func (ic *IcecastController) statusUpdater() { ...@@ -121,7 +119,7 @@ func (ic *IcecastController) statusUpdater() {
} }
func (ic *IcecastController) fetchStatus() (*IcecastStatus, error) { 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 { if err != nil {
return nil, err return nil, err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment