示例#1
0
文件: rodis.go 项目: aegsea/rodis
func main() {
	configFile := flag.String("c", "rodis.toml", "Rodis config file path")
	flag.Parse()

	if err := config.LoadConfig(*configFile); err != nil {
		log6.Fatal("Load/Parse config file error: %v", err)
	}
	log6.ParseLevel(config.Config.LogLevel)

	runtime.GOMAXPROCS(runtime.NumCPU())

	err := storage.OpenStorage(config.Config.LevelDBPath, config.Config.LevelDB)
	if err != nil {
		log6.Fatal("Open storage error: %v", err)
	}
	defer storage.CloseStorage()

	rs, err := net.NewServer(config.Config)
	if err != nil {
		log6.Fatal("New server error: %v", err)
	}

	defer rs.Close()

	sc := make(chan os.Signal, 1)
	signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

	go rs.Run()

	<-sc
}
示例#2
0
文件: server.go 项目: aegsea/rodis
func (rs *rodisServer) Run() {
	log6.Info("Server is starting, listen on %v", rs.cfg.Listen)

	listener, err := net.Listen("tcp", rs.cfg.Listen)
	if err != nil {
		log6.Fatal("Server listen on %v failure: %v", rs.cfg.Listen, err)
		return
	}

	rs.listener = listener
	rs.started = true

	for {
		conn, err := rs.listener.Accept()
		if err != nil {
			select {
			case <-rs.quit:
				return
			default:
				log6.Warn("Server accepts connection error: %v", err)
			}
			continue
		}

		go newConnection(conn, rs)
	}
}