Esempio n. 1
0
func main() {
	flag.Parse()

	// Always use the maximum available CPU/Cores
	runtime.GOMAXPROCS(runtime.NumCPU())

	if !initLogger() {
		return
	}

	if !initDatabases() {
		return
	}

	// init action
	if !handler.InitAction() {
		return
	}

	if !world.InitWorld() {
		return
	}

	gameServer := server.NewServer()
	gameServer.Start()

}
Esempio n. 2
0
func NewCenter() *Center {
	flag.StringVar(&host, "host", "127.0.0.1", "blance host.")
	flag.StringVar(&port, "port", "8090", "blance port.")

	return &Center{
		server:   server.NewServer(),
		cmanager: mclient.NewManager(),
	}
}
Esempio n. 3
0
func NewCoServer() *CoServer {
	ctx := context.GetContext()
	coServ, ok := ctx.GetComponent("coserver").(*CoServer)
	if ok == true {
		return coServ
	}
	serv := server.NewServer()
	coServ = &CoServer{serv}
	seelog.Infof("<%v> component server created", ctx.GetServerID())
	return coServ
}
Esempio n. 4
0
func main() {
	srv := server.NewServer(&opts)

	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

	srv.Main()

	<-sigChan
	//srv.logf("jon_server quit")
}
Esempio n. 5
0
File: server.go Progetto: intfrr/upd
func main() {
	flags := parseFlags()

	config, err := readFromFile(flags.ConfigFile)
	if err != nil {
		log.Println("[warn] Can't read the configuration file")
		log.Println("[warn] Falling back on default values for configuration.")
	}

	app := server.NewServer(config)
	app.Start()
}
Esempio n. 6
0
func main() {
	echoSrv := &EchoServer{}
	var downAddrs []string = []string{"0.0.0.0:1234", "0.0.0.0:2345"}
	srv := server.NewServer(echoSrv, "0.0.0.0:5678", downAddrs, 5000)

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

	srv.Main()

	<-sigChan
	srv.Exit()
}
Esempio n. 7
0
File: db.go Progetto: mysll/flynet
func main() {
	flag.Parse()
	if *master == "" || *startargs == "" {
		flag.PrintDefaults()
		panic("args error")
	}

	App.Server = server.NewServer(App, int32(*appid))
	if App.Start(*master, *localip, *outerip, *typ, *startargs) {
		App.Wait()
	}

}
Esempio n. 8
0
func main() {
	config.InitConfig()

	if config.EnableProfile {
		defer profile.Start(profile.CPUProfile).Stop()
	}

	runtime.GOMAXPROCS(runtime.NumCPU() * 3)
	utils.InitLogger()
	if config.RC.MySQLEnabled {
		query.RC_MySQLConf = config.RC.MySQLConf
		query.InitMySQL(query.RC_MySQLConf)
	}
	server.NewServer()

}
Esempio n. 9
0
func main() {
	srv := server.NewServer(8080)
	srv.Start()
}
Esempio n. 10
0
func main() {
	fileName := flag.String("config", "config.toml.sample", "Config file")
	wantsVersion := flag.Bool("v", false, "Get version number")
	resetRootPassword := flag.Bool("reset-root", false, "Reset root password")
	pidFile := flag.String("pidfile", "", "the pid file")
	cpuProfiler := flag.String("cpuprofile", "", "filename where cpu profile data will be written")

	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	startProfiler(cpuProfiler)

	if wantsVersion != nil && *wantsVersion {
		fmt.Printf("InfluxDB v%s (git: %s)\n", version, gitSha)
		return
	}
	config := configuration.LoadConfiguration(*fileName)
	setupLogging(config.LogLevel, config.LogFile)

	if pidFile != nil && *pidFile != "" {
		pid := strconv.Itoa(os.Getpid())
		if err := ioutil.WriteFile(*pidFile, []byte(pid), 0644); err != nil {
			panic(err)
		}
	}

	log.Info("Starting Influx Server...")
	log.Info(`
+---------------------------------------------+
|  _____        __ _            _____  ____   |
| |_   _|      / _| |          |  __ \|  _ \  |
|   | |  _ __ | |_| |_   ___  _| |  | | |_) | |
|   | | | '_ \|  _| | | | \ \/ / |  | |  _ <  |
|  _| |_| | | | | | | |_| |>  <| |__| | |_) | |
| |_____|_| |_|_| |_|\__,_/_/\_\_____/|____/  |
+---------------------------------------------+

`)
	os.MkdirAll(config.RaftDir, 0744)
	os.MkdirAll(config.DataDir, 0744)
	server, err := server.NewServer(config)
	if err != nil {
		panic(err)
	}

	if *resetRootPassword {
		// TODO: make this not suck
		// This is ghetto as hell, but it'll work for now.
		go func() {
			time.Sleep(2 * time.Second) // wait for the raft server to join the cluster

			log.Warn("Resetting root's password to %s", coordinator.DEFAULT_ROOT_PWD)
			if err := server.RaftServer.CreateRootUser(); err != nil {
				panic(err)
			}
		}()
	}
	err = server.ListenAndServe()
	if err != nil {
		log.Error("ListenAndServe failed: ", err)
	}
}
Esempio n. 11
0
func startServer() (*server.Server, string) {
	s := server.NewServer("127.0.0.1", 9999, stateCh)
	go s.Start()
	return s, waitForData("(system)")
}
Esempio n. 12
0
func main() {
	fileName := flag.String("config", "config.sample.toml", "Config file")
	wantsVersion := flag.Bool("v", false, "Get version number")
	resetRootPassword := flag.Bool("reset-root", false, "Reset root password")
	hostname := flag.String("hostname", "", "Override the hostname, the `hostname` config option will be overridden")
	raftPort := flag.Int("raft-port", 0, "Override the raft port, the `raft.port` config option will be overridden")
	protobufPort := flag.Int("protobuf-port", 0, "Override the protobuf port, the `protobuf_port` config option will be overridden")
	pidFile := flag.String("pidfile", "", "the pid file")
	repairLeveldb := flag.Bool("repair-ldb", false, "set to true to repair the leveldb files")

	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()

	version := fmt.Sprintf("InfluxDB v%s (git: %s) (leveldb: %d.%d)", version, gitSha, levigo.GetLevelDBMajorVersion(), levigo.GetLevelDBMinorVersion())
	if wantsVersion != nil && *wantsVersion {
		fmt.Println(version)
		return
	}
	config := configuration.LoadConfiguration(*fileName)

	// override the hostname if it was specified on the command line
	if hostname != nil && *hostname != "" {
		config.Hostname = *hostname
	}

	if raftPort != nil && *raftPort != 0 {
		config.RaftServerPort = *raftPort
	}

	if protobufPort != nil && *protobufPort != 0 {
		config.ProtobufPort = *protobufPort
	}

	config.Version = version

	setupLogging(config.LogLevel, config.LogFile)

	if *repairLeveldb {
		log.Info("Repairing leveldb")
		files, err := ioutil.ReadDir(config.DataDir)
		if err != nil {
			panic(err)
		}
		o := levigo.NewOptions()
		defer o.Close()
		for _, f := range files {
			p := path.Join(config.DataDir, f.Name())
			log.Info("Repairing %s", p)
			if err := levigo.RepairDatabase(p, o); err != nil {
				panic(err)
			}
		}
	}

	if pidFile != nil && *pidFile != "" {
		pid := strconv.Itoa(os.Getpid())
		if err := ioutil.WriteFile(*pidFile, []byte(pid), 0644); err != nil {
			panic(err)
		}
	}

	if config.BindAddress == "" {
		log.Info("Starting Influx Server %s...", version)
	} else {
		log.Info("Starting Influx Server %s bound to %s...", version, config.BindAddress)
	}
	fmt.Printf(`
+---------------------------------------------+
|  _____        __ _            _____  ____   |
| |_   _|      / _| |          |  __ \|  _ \  |
|   | |  _ __ | |_| |_   ___  _| |  | | |_) | |
|   | | | '_ \|  _| | | | \ \/ / |  | |  _ <  |
|  _| |_| | | | | | | |_| |>  <| |__| | |_) | |
| |_____|_| |_|_| |_|\__,_/_/\_\_____/|____/  |
+---------------------------------------------+

`)
	os.MkdirAll(config.RaftDir, 0744)
	os.MkdirAll(config.DataDir, 0744)
	server, err := server.NewServer(config)
	if err != nil {
		// sleep for the log to flush
		time.Sleep(time.Second)
		panic(err)
	}

	if err := startProfiler(server); err != nil {
		panic(err)
	}

	if *resetRootPassword {
		// TODO: make this not suck
		// This is ghetto as hell, but it'll work for now.
		go func() {
			time.Sleep(2 * time.Second) // wait for the raft server to join the cluster

			log.Warn("Resetting root's password to %s", coordinator.DEFAULT_ROOT_PWD)
			if err := server.RaftServer.CreateRootUser(); err != nil {
				panic(err)
			}
		}()
	}
	err = server.ListenAndServe()
	if err != nil {
		log.Error("ListenAndServe failed: ", err)
	}
}
Esempio n. 13
0
func main() {
	s := server.NewServer(settings.SERVER, settings.PORT, nil)
	s.Start()
}
Esempio n. 14
0
func main() {
	tcp_port := flag.String("p", "11211", "TCP Port to listen (non required - default port is 11211)")
	memory_amount_mb := flag.Int("m", 0, "Amount of memory to allocate (MiB)")
	daemonize := flag.Bool("d", false, "Run process as background")
	// unix_socket := flag.String("s", "", "Unix socket path to listen on (disables network support)")
	// unix_perms := flag.String("a", "", "Permissions (in octal format) for Unix socket created with -s option")
	listen_ip := flag.String("l", "", "Listen on specified ip addr only; default to any address.")
	max_connections := flag.Int("c", 1024, "Use max simultaneous connections;")
	udp_port := flag.String("U", "", "UDP Port to listen (default is empty string - which means it is turned off)")
	disable_cas := flag.Bool("C", false, "Disabling of cas command support.")
	disable_flush := flag.Bool("F", false, "Disabling of flush_all command support.")
	help := flag.Bool("h", false, "Show usage manual and list of options.")
	verbose := flag.Bool("v", false, "Turning verbosity on. This option includes errors and warnings only.")
	deep_verbose := flag.Bool("vv", false, "Turning deep verbosity on. This option includes requests, responses and same output as simple verbosity.")
	flag.Parse()

	if *help {
		// TODO: It should be spread in future.
		fmt.Println("MemoranGo - memory caching service.\nusage:\nmemorango -m <memory_to_alloc> [-CvhFvvd]\n" +
			"\t[-l <listen_ip>] [-c <limit_connections>] [-p <tcp_port>] [-U <udp_port>]")
		return
	}

	if *memory_amount_mb <= 0 {
		fmt.Println("Impossible to run server with incorrect specified amount of available data.")
		return
	}

	var verbosity = 0
	if *deep_verbose {
		verbosity = 2
	} else if *verbose {
		verbosity = 1
	}

	if *daemonize {
		var transacted_options = []string{}
		dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
		transacted_options = append(transacted_options, filepath.Join(dir, os.Args[0]), "-p", *tcp_port, "-m",
			tools.IntToString(int64(*memory_amount_mb)),
			"-c", tools.IntToString(int64(*max_connections)))
		if len(*listen_ip) > 0 {
			transacted_options = append(transacted_options, "-l", *listen_ip)
		}
		if len(*udp_port) > 0 {
			transacted_options = append(transacted_options, "-U", *udp_port)
		}
		if *disable_cas {
			transacted_options = append(transacted_options, "-C")
		}
		if *disable_flush {
			transacted_options = append(transacted_options, "-F")
		}
		if verbosity == 1 {
			transacted_options = append(transacted_options, "-v")
		} else if verbosity == 2 {
			transacted_options = append(transacted_options, "-vv")
		}
		transacted_options = append(transacted_options, "&")
		fmt.Printf("Run %s daemon at 127.0.0.1:%s with %d MiB allowed memory.\n", tools.VERSION, *tcp_port, *memory_amount_mb)
		cmd := exec.Command("/usr/bin/nohup", transacted_options...)
		start_err := cmd.Start()
		if start_err != nil {
			fmt.Println("Status: ", start_err)
		}
	} else {
		fmt.Printf("%d Run %s on 127.0.0.1:%s with %d MiB allowed memory.\n",
			os.Getpid(), tools.VERSION, *tcp_port, *memory_amount_mb)
		_server := server.NewServer(*tcp_port, *udp_port, *listen_ip, *max_connections, *disable_cas, *disable_flush,
			verbosity, int64(*memory_amount_mb)*1024*1024 /* let's convert to bytes */)
		_server.RunServer()
		defer _server.StopServer()
		_server.Wait()
	}
}
Esempio n. 15
0
func main() {
	flags := parseFlags()

	app := server.NewServer(flags)
	app.Start()
}