Example #1
0
func main() {
	if configFileName == nil {
		fmt.Println("without specifiy config file.")
		os.Exit(1)
	}
	config, md, err := LoadCmdConfig(*configFileName)
	if err != nil {
		os.Exit(1)
	}
	cmddConfig = &CmddConfig{BasicSvrConfig: BasicSvrConfig{ErrorLog: true, AccessLog: false},
		ListenAddr: ":9000", ConfigDir: "/cmds"}
	err = analyzeCmddConf(config, md)
	if err != nil {
		os.Exit(1)
	}

	err = cmdlog.InitLog("cmdServer", cmddConfig.ErrorLog, cmddConfig.AccessLog)
	if err != nil {
		os.Exit(1)
	}
	configClient = etcd.NewClient(cmddConfig.ConfigServers)
	err = registerToConfigServer()
	if err != nil {
		os.Exit(1)
	}

	err = cmds.InitHandlerConf(config, md)
	if err != nil {
		os.Exit(1)
	}

	cmdServer := &http.Server{Addr: cmddConfig.ListenAddr, Handler: cmds.CmdServerMux}
	err = cmdServer.ListenAndServe()
	if err != nil {
		fmt.Printf("%s", err.Error())
	}
}
Example #2
0
func main() {
	if configFileName == nil {
		fmt.Println("without specifiy config file.")
		os.Exit(1)
	}
	config, md, err := LoadFmdConfig(*configFileName)
	if err != nil {
		log.Fatal(err.Error())
	}
	fmConf = &FmdConfig{BasicSvrConfig: BasicSvrConfig{ErrorLog: true, AccessLog: false},
		FastcgiListenAddr: ":11000", HttpListenAddr: ":11001"}
	err = analyzeFmdConf(config, md)
	if err != nil {
		log.Fatal(err.Error())
	}

	err = dlog.InitLog("ngxfmd", fmConf.ErrorLog, fmConf.AccessLog)
	if err != nil {
		log.Fatal(err.Error())
	}

	err = cmds.InitHandlerConf(config, md)
	if err != nil {
		log.Fatal(err.Error())
	}
	cmdServer := &http.Server{Addr: fmConf.HttpListenAddr, Handler: cmds.CmdServerMux}
	err = cmdServer.ListenAndServe()
	if err != nil {
		fmt.Printf("%s", err.Error())
	}
	// var wg sync.WaitGroup
	// wg.Add(1)
	go func() {
		cmdServer := &http.Server{Addr: fmConf.HttpListenAddr, Handler: cmds.CmdServerMux}
		err = cmdServer.ListenAndServe()
		if err != nil {
			fmt.Printf("%s", err.Error())
		}
		// wg.Done()
	}()
	// wg.Add(1)
	go func() {
		ln, err := net.Listen("tcp", fmConf.FastcgiListenAddr)
		if err != nil {
			log.Fatal(err.Error())
		}

		err = fcgi.Serve(ln, cmds.CmdServerMux)
		if err != nil {
			log.Fatal(err.Error())
		}
		// wg.Done()
	}()
	// wg.Wait()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	// Block until a signal is received.
	s := <-c
	cmds.Uninit()
	dlog.Printf("Accept %s signal, quit server...\n", s.String())
}