Don't bother starting without GUI (fixes #156)
This commit is contained in:
parent
4f2fe07ae4
commit
1e92c47960
|
@ -7,6 +7,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
@ -34,7 +35,12 @@ const (
|
|||
unchangedPassword = "--password-unchanged--"
|
||||
)
|
||||
|
||||
func startGUI(cfg GUIConfiguration, m *Model) {
|
||||
func startGUI(cfg GUIConfiguration, m *Model) error {
|
||||
l, err := net.Listen("tcp", cfg.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
router := martini.NewRouter()
|
||||
router.Get("/", getRoot)
|
||||
router.Get("/rest/version", restGetVersion)
|
||||
|
@ -51,21 +57,19 @@ func startGUI(cfg GUIConfiguration, m *Model) {
|
|||
router.Post("/rest/error", restPostError)
|
||||
router.Post("/rest/error/clear", restClearErrors)
|
||||
|
||||
go func() {
|
||||
mr := martini.New()
|
||||
if len(cfg.User) > 0 && len(cfg.Password) > 0 {
|
||||
mr.Use(basic(cfg.User, cfg.Password))
|
||||
}
|
||||
mr.Use(static)
|
||||
mr.Use(martini.Recovery())
|
||||
mr.Use(restMiddleware)
|
||||
mr.Action(router.Handle)
|
||||
mr.Map(m)
|
||||
err := http.ListenAndServe(cfg.Address, mr)
|
||||
if err != nil {
|
||||
warnln("GUI not possible:", err)
|
||||
}
|
||||
}()
|
||||
mr := martini.New()
|
||||
if len(cfg.User) > 0 && len(cfg.Password) > 0 {
|
||||
mr.Use(basic(cfg.User, cfg.Password))
|
||||
}
|
||||
mr.Use(static)
|
||||
mr.Use(martini.Recovery())
|
||||
mr.Use(restMiddleware)
|
||||
mr.Action(router.Handle)
|
||||
mr.Map(m)
|
||||
|
||||
go http.Serve(l, mr)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getRoot(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -233,7 +233,7 @@ func main() {
|
|||
if cfg.GUI.Enabled && cfg.GUI.Address != "" {
|
||||
addr, err := net.ResolveTCPAddr("tcp", cfg.GUI.Address)
|
||||
if err != nil {
|
||||
warnf("Cannot start GUI on %q: %v", cfg.GUI.Address, err)
|
||||
fatalf("Cannot start GUI on %q: %v", cfg.GUI.Address, err)
|
||||
} else {
|
||||
var hostOpen, hostShow string
|
||||
switch {
|
||||
|
@ -249,7 +249,10 @@ func main() {
|
|||
}
|
||||
|
||||
infof("Starting web GUI on http://%s:%d/", hostShow, addr.Port)
|
||||
startGUI(cfg.GUI, m)
|
||||
err := startGUI(cfg.GUI, m)
|
||||
if err != nil {
|
||||
fatalln("Cannot start GUI:", err)
|
||||
}
|
||||
if cfg.Options.StartBrowser && len(os.Getenv("STRESTART")) == 0 {
|
||||
openURL(fmt.Sprintf("http://%s:%d", hostOpen, addr.Port))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue