Exemplo n.º 1
0
Arquivo: main.go Projeto: uwork/gorond
func doMain(configPath string, includeDir string, pidPath string) int {

	// load config.
	config, err := config.LoadConfig(configPath, includeDir)
	if err != nil {
		log.Println(err)
		return -1
	}

	// start goron.
	grn, err := goron.NewGorond(config)
	if err != nil {
		log.Println(err)
		return -1
	}

	// Goronデーモンの開始
	grn.Start()

	// API サーバの開始
	if grn.Config.Config.WebApi != "" {
		webapi.SetLogger(config.Config.ApiLog)
		server, err := webapi.NewWebApiServer(grn.Config.Config.WebApi, grn)
		if err != nil {
			log.Println(err)
			return -2
		}

		wc := make(chan os.Signal)
		wsc := make(chan error)
		signal.Notify(wc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
		err = server.Start(wc, wsc)
		if err != nil {
			log.Println(err)
			return -2
		}
	}

	// create pid file.
	err = util.SavePidFile(pidPath)
	if err != nil {
		log.Println(err)
		return -3
	}
	defer os.Remove(pidPath)

	log.Println("wait for signal")

	// wait for terminate.
	c := make(chan os.Signal)
	sc := make(chan int, 1)
	signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
	go goron.WaitSignal(c, sc)

	return <-sc
}
Exemplo n.º 2
0
// テスト用のサーバを作成
func createTestServer(t *testing.T) (*WebApiServer, chan os.Signal, chan error) {
	conf, err := config.LoadConfig("webapi_test.conf", "config_test.d")
	if err != nil {
		t.Error(err)
	}
	grn, err := goron.NewGorond(conf)
	if err != nil {
		t.Error(err)
	}

	server, err := NewWebApiServer(grn.Config.Config.WebApi, grn)
	if err != nil {
		t.Error(err)
		os.Exit(-1)
	}

	wc := make(chan os.Signal)
	wsc := make(chan error)
	signal.Notify(wc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

	return server, wc, wsc
}