2020-04-24 19:38:21 +02:00
|
|
|
// Copyright (c) 2020 by Juliusz Chroboczek.
|
|
|
|
|
|
|
|
// This is not open source software. Copy it, and I'll break into your
|
|
|
|
// house and tell your three year-old that Santa doesn't exist.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"path/filepath"
|
2020-05-20 23:04:31 +02:00
|
|
|
"runtime"
|
|
|
|
"runtime/pprof"
|
2020-04-24 19:38:21 +02:00
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
var httpAddr string
|
|
|
|
var staticRoot string
|
|
|
|
var dataDir string
|
2020-04-25 02:25:51 +02:00
|
|
|
var groupsDir string
|
2020-05-23 01:48:36 +02:00
|
|
|
var recordingsDir string
|
2020-04-24 19:38:21 +02:00
|
|
|
var iceFilename string
|
|
|
|
|
|
|
|
func main() {
|
2020-05-20 23:04:31 +02:00
|
|
|
var cpuprofile, memprofile, mutexprofile string
|
|
|
|
|
2020-04-24 19:38:21 +02:00
|
|
|
flag.StringVar(&httpAddr, "http", ":8443", "web server `address`")
|
|
|
|
flag.StringVar(&staticRoot, "static", "./static/",
|
|
|
|
"web server root `directory`")
|
|
|
|
flag.StringVar(&dataDir, "data", "./data/",
|
|
|
|
"data `directory`")
|
2020-04-25 02:25:51 +02:00
|
|
|
flag.StringVar(&groupsDir, "groups", "./groups/",
|
|
|
|
"group description `directory`")
|
2020-05-23 01:48:36 +02:00
|
|
|
flag.StringVar(&recordingsDir, "recordings", "./recordings/",
|
|
|
|
"recordings `directory`")
|
2020-05-20 23:04:31 +02:00
|
|
|
flag.StringVar(&cpuprofile, "cpuprofile", "",
|
|
|
|
"store CPU profile in `file`")
|
|
|
|
flag.StringVar(&memprofile, "memprofile", "",
|
|
|
|
"store memory profile in `file`")
|
|
|
|
flag.StringVar(&mutexprofile, "mutexprofile", "",
|
|
|
|
"store mutex profile in `file`")
|
2020-04-24 19:38:21 +02:00
|
|
|
flag.Parse()
|
2020-05-20 23:04:31 +02:00
|
|
|
|
|
|
|
if cpuprofile != "" {
|
|
|
|
f, err := os.Create(cpuprofile)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Create(cpuprofile): %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pprof.StartCPUProfile(f)
|
|
|
|
defer func() {
|
|
|
|
pprof.StopCPUProfile()
|
|
|
|
f.Close()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
if memprofile != "" {
|
|
|
|
defer func() {
|
|
|
|
f, err := os.Create(memprofile)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Create(memprofile): %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pprof.WriteHeapProfile(f)
|
|
|
|
f.Close()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
if mutexprofile != "" {
|
|
|
|
runtime.SetMutexProfileFraction(1)
|
|
|
|
defer func() {
|
|
|
|
f, err := os.Create(mutexprofile)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Create(mutexprofile): %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pprof.Lookup("mutex").WriteTo(f, 0)
|
|
|
|
f.Close()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-08-07 11:14:34 +02:00
|
|
|
iceFilename = filepath.Join(dataDir, "ice-servers.json")
|
2020-04-24 19:38:21 +02:00
|
|
|
|
2020-04-25 04:08:43 +02:00
|
|
|
go readPublicGroups()
|
2020-05-31 16:46:41 +02:00
|
|
|
webserver()
|
2020-04-24 19:38:21 +02:00
|
|
|
|
|
|
|
terminate := make(chan os.Signal, 1)
|
2020-09-12 12:42:48 +02:00
|
|
|
signal.Notify(terminate, syscall.SIGINT, syscall.SIGTERM)
|
2020-04-24 19:38:21 +02:00
|
|
|
<-terminate
|
2020-09-12 12:42:48 +02:00
|
|
|
shutdown()
|
2020-04-24 19:38:21 +02:00
|
|
|
}
|