mirror of
https://github.com/jech/galene.git
synced 2024-11-09 18:25:58 +01:00
Rework synchronisation between webserver and main.
We now exit with an error code if the webserver couldn't start.
This commit is contained in:
parent
aeb8540ad4
commit
f5cb2ff328
2 changed files with 25 additions and 14 deletions
18
sfu.go
18
sfu.go
|
@ -81,10 +81,22 @@ func main() {
|
||||||
group.IceFilename = filepath.Join(dataDir, "ice-servers.json")
|
group.IceFilename = filepath.Join(dataDir, "ice-servers.json")
|
||||||
|
|
||||||
go group.ReadPublicGroups()
|
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)
|
terminate := make(chan os.Signal, 1)
|
||||||
signal.Notify(terminate, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(terminate, syscall.SIGINT, syscall.SIGTERM)
|
||||||
<-terminate
|
select {
|
||||||
webserver.Shutdown()
|
case <-terminate:
|
||||||
|
webserver.Shutdown()
|
||||||
|
case <-serverDone:
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ var server *http.Server
|
||||||
|
|
||||||
var StaticRoot string
|
var StaticRoot string
|
||||||
|
|
||||||
func Serve(address string, dataDir string) {
|
func Serve(address string, dataDir string) error {
|
||||||
http.Handle("/", &fileHandler{http.Dir(StaticRoot)})
|
http.Handle("/", &fileHandler{http.Dir(StaticRoot)})
|
||||||
http.HandleFunc("/group/", groupHandler)
|
http.HandleFunc("/group/", groupHandler)
|
||||||
http.HandleFunc("/recordings",
|
http.HandleFunc("/recordings",
|
||||||
|
@ -61,16 +61,15 @@ func Serve(address string, dataDir string) {
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
go func() {
|
|
||||||
var err error
|
err := server.ListenAndServeTLS(
|
||||||
err = server.ListenAndServeTLS(
|
filepath.Join(dataDir, "cert.pem"),
|
||||||
filepath.Join(dataDir, "cert.pem"),
|
filepath.Join(dataDir, "key.pem"),
|
||||||
filepath.Join(dataDir, "key.pem"),
|
)
|
||||||
)
|
if err == http.ErrServerClosed {
|
||||||
if err != nil && err != http.ErrServerClosed {
|
return nil
|
||||||
log.Printf("ListenAndServeTLS: %v", err)
|
}
|
||||||
}
|
return err
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func mungeHeader(w http.ResponseWriter) {
|
func mungeHeader(w http.ResponseWriter) {
|
||||||
|
|
Loading…
Reference in a new issue