ledisdb/cmd/ledis-server/main.go

57 lines
891 B
Go
Raw Normal View History

2014-05-05 07:37:44 +04:00
package main
import (
"flag"
"github.com/siddontang/ledisdb/server"
2014-05-05 07:37:44 +04:00
"os"
"os/signal"
2014-05-09 05:17:28 +04:00
"runtime"
2014-05-05 07:37:44 +04:00
"syscall"
)
2014-06-11 10:52:34 +04:00
var configFile = flag.String("config", "/etc/ledis.json", "ledisdb config file")
2014-07-25 20:46:03 +04:00
var storeName = flag.String("store", "", "select a store to use, it will overwrite the config's store")
2014-05-05 07:37:44 +04:00
func main() {
2014-05-09 05:17:28 +04:00
runtime.GOMAXPROCS(runtime.NumCPU())
2014-05-05 07:37:44 +04:00
flag.Parse()
if len(*configFile) == 0 {
2014-07-02 06:13:10 +04:00
println("must use a config file")
return
2014-05-05 07:37:44 +04:00
}
cfg, err := server.NewConfigWithFile(*configFile)
2014-05-05 07:37:44 +04:00
if err != nil {
2014-07-02 06:13:10 +04:00
println(err.Error())
return
2014-05-05 07:37:44 +04:00
}
2014-07-25 20:46:03 +04:00
if len(*storeName) > 0 {
cfg.DB.Name = *storeName
}
var app *server.App
app, err = server.NewApp(cfg)
2014-05-05 07:37:44 +04:00
if err != nil {
2014-07-02 06:13:10 +04:00
println(err.Error())
return
2014-05-05 07:37:44 +04:00
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-sc
app.Close()
}()
app.Run()
}