2014-07-08 10:59:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-15 19:46:22 +00:00
|
|
|
"fmt"
|
2014-07-08 10:59:16 +00:00
|
|
|
"github.com/stvp/rollbar"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"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-12 10:58:56 +00:00
|
|
|
|
2014-07-08 10:59:16 +00:00
|
|
|
SaveState()
|
2014-07-12 10:42:26 +00:00
|
|
|
Log("State successfully persisted")
|
2014-07-12 10:58:56 +00:00
|
|
|
|
2014-07-08 10:59:16 +00:00
|
|
|
storage.Close()
|
2014-07-12 10:42:26 +00:00
|
|
|
Log("Storage closed")
|
2014-07-12 10:58:56 +00:00
|
|
|
|
|
|
|
Log("Waiting for rollbar...")
|
|
|
|
rollbar.Wait()
|
|
|
|
|
|
|
|
Log("Stopped")
|
|
|
|
os.Exit(0)
|
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() {
|
|
|
|
SetupConfig()
|
2014-07-12 10:58:56 +00:00
|
|
|
SetupLogging()
|
2014-07-10 12:19:39 +00:00
|
|
|
SetupStorage()
|
|
|
|
SetupServer()
|
|
|
|
HandleShutdown()
|
|
|
|
LoadState()
|
2014-07-08 10:59:16 +00:00
|
|
|
go KeepStatePersisted()
|
|
|
|
go PersistMessages()
|
|
|
|
|
|
|
|
|
2014-07-15 19:46:22 +00:00
|
|
|
port := fmt.Sprintf(":%d", Config.Port)
|
|
|
|
http.ListenAndServe(port, nil)
|
2014-07-08 10:59:16 +00:00
|
|
|
}
|