1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 23:35:46 +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:
Juliusz Chroboczek 2020-09-18 14:14:26 +02:00
parent aeb8540ad4
commit f5cb2ff328
2 changed files with 25 additions and 14 deletions

18
sfu.go
View file

@ -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
webserver.Shutdown()
select {
case <-terminate:
webserver.Shutdown()
case <-serverDone:
os.Exit(1)
}
}

View file

@ -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(
filepath.Join(dataDir, "cert.pem"),
filepath.Join(dataDir, "key.pem"),
)
if err != nil && err != http.ErrServerClosed {
log.Printf("ListenAndServeTLS: %v", err)
}
}()
err := server.ListenAndServeTLS(
filepath.Join(dataDir, "cert.pem"),
filepath.Join(dataDir, "key.pem"),
)
if err == http.ErrServerClosed {
return nil
}
return err
}
func mungeHeader(w http.ResponseWriter) {