Exemple #1
0
func runServerWithMode(c *cli.Context, devMode bool, deamonMode bool) {
	var command []string

	if devMode {
		proxyPort := c.Int("port")

		command = []string{
			"gin",
			"-g",
			"-p", strconv.Itoa(int(proxyPort)),
			"-a", strconv.Itoa(int(utils.Cfg.ServerSettings.Ports[0])),
			"-b", os.Args[0],
			"r",
			"--",
		}
	} else {
		command = []string{os.Args[0]}
	}

	i := len(command)
	args := make([]string, i+len(os.Args))
	copy(args, command)

	for _, arg := range os.Args[1:] {
		if devMode && arg == "--dev" {
			continue
		}
		if deamonMode && (arg == "--deamon" || arg == "-d") {
			continue
		}

		args[i] = arg
		i++
	}

	cmd := exec.Command(
		args[0],
		args[1:]...,
	)

	if deamonMode {
		cmd.Start()
		if err := utils.WritePidfile(GIN_PIDFILE, cmd.Process.Pid); err != nil {
			fmt.Println(err.Error())
			os.Exit(1)
		}
	} else {
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		if err := cmd.Run(); err != nil {
			fmt.Println(err)
			fmt.Println("You'll need to have gin installed: https://github.com/codegangsta/gin")
			os.Exit(1)
		}
	}
}
Exemple #2
0
func runServerAction(c *cli.Context) {
	configFilePath := c.GlobalString("config")
	utils.LoadConfig(configFilePath)

	devMode := c.Bool("dev")
	deamonMode := c.Bool("deamon")

	if devMode || deamonMode {
		runServerWithMode(c, devMode, deamonMode)
	} else {
		if err := utils.WritePidfile(SERVER_PIDFILE, os.Getpid()); err != nil {
			fmt.Println(err.Error())
			os.Exit(1)
		}

		store.InitClient()
		store.MigrateModels()
		api.ServeApi()
	}
}