2014-07-08 10:59:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
2014-07-29 06:31:42 +00:00
|
|
|
const (
|
|
|
|
Version = "0.1.3"
|
|
|
|
)
|
|
|
|
|
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-16 17:50:05 +00:00
|
|
|
CloseStorage()
|
2014-07-12 10:58:56 +00:00
|
|
|
|
|
|
|
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()
|
2014-07-29 06:56:46 +00:00
|
|
|
StartServer()
|
2014-07-08 10:59:16 +00:00
|
|
|
}
|