Commit f5cb2ff3 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Rework synchronisation between webserver and main.

We now exit with an error code if the webserver couldn't start.
parent aeb8540a
......@@ -81,10 +81,22 @@ func main() {
group.IceFilename = filepath.Join(dataDir, "ice-servers.json")
go group.ReadPublicGroups()
webserver.Serve(httpAddr, dataDir)
serverDone := make(chan struct{})
go func() {
err := webserver.Serve(httpAddr, dataDir)
if err != nil {
log.Printf("Server: %v", err)
}
close(serverDone)
}()
terminate := make(chan os.Signal, 1)
signal.Notify(terminate, syscall.SIGINT, syscall.SIGTERM)
<-terminate
select {
case <-terminate:
webserver.Shutdown()
case <-serverDone:
os.Exit(1)
}
}
......@@ -29,7 +29,7 @@ var server *http.Server
var StaticRoot string
func Serve(address string, dataDir string) {
func Serve(address string, dataDir string) error {
http.Handle("/", &fileHandler{http.Dir(StaticRoot)})
http.HandleFunc("/group/", groupHandler)
http.HandleFunc("/recordings",
......@@ -61,16 +61,15 @@ func Serve(address string, dataDir string) {
return true
})
})
go func() {
var err error
err = server.ListenAndServeTLS(
err := server.ListenAndServeTLS(
filepath.Join(dataDir, "cert.pem"),
filepath.Join(dataDir, "key.pem"),
)
if err != nil && err != http.ErrServerClosed {
log.Printf("ListenAndServeTLS: %v", err)
if err == http.ErrServerClosed {
return nil
}
}()
return err
}
func mungeHeader(w http.ResponseWriter) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment