1
0
Fork 0
burlesque/main.go

43 lines
710 B
Go
Raw Normal View History

2014-07-08 10:59:16 +00:00
package main
import (
"github.com/stvp/rollbar"
"net/http"
"os"
"os/signal"
"runtime"
"syscall"
)
2014-07-10 12:19:39 +00:00
func HandleShutdown() {
ch := make(chan os.Signal)
signal.Notify(ch, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT)
2014-07-08 10:59:16 +00:00
go func() {
2014-07-10 12:19:39 +00:00
<-ch
2014-07-08 10:59:16 +00:00
SaveState()
2014-07-12 10:42:26 +00:00
Log("State successfully persisted")
2014-07-08 10:59:16 +00:00
storage.Close()
rollbar.Wait()
2014-07-12 10:42:26 +00:00
Log("Storage closed")
Log("Server stopped")
2014-07-10 12:19:39 +00:00
os.Exit(1)
2014-07-08 10:59:16 +00:00
}()
2014-07-10 12:19:39 +00:00
}
2014-07-08 10:59:16 +00:00
2014-07-10 12:19:39 +00:00
func main() {
2014-07-12 10:42:26 +00:00
SetupLogging()
2014-07-10 12:19:39 +00:00
SetupConfig()
SetupStorage()
SetupServer()
HandleShutdown()
LoadState()
2014-07-08 10:59:16 +00:00
go KeepStatePersisted()
go PersistMessages()
2014-07-12 10:42:26 +00:00
Log("GOMAXPROCS = %d", runtime.GOMAXPROCS(-1))
Log("Starting HTTP server on port %d", cfg.Port)
2014-07-08 10:59:16 +00:00
2014-07-10 12:19:39 +00:00
http.ListenAndServe(cfg.PortString(), nil)
2014-07-08 10:59:16 +00:00
}