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