示例#1
0
func main() {
	var (
		ch       chan bool = make(chan bool)
		confFile string
		httpPort int
		help     bool
		newApp   *core.MainApp
	)

	flag.IntVar(&httpPort, "port", 14280, "web server port")
	flag.BoolVar(&help, "help", false, "command usage")
	flag.StringVar(&confFile, "conf", "app.conf", "")
	flag.Parse()

	if help {
		flag.Usage()
		return
	}
	log.SetOutput(os.Stdout)
	log.SetFlags(log.LstdFlags | log.Ltime | log.Ldate | log.Lshortfile)
	runtime.GOMAXPROCS(runtime.NumCPU())
	newApp = core.NewMainApp(confFile)
	go fix.SignalNotify(ch)
	go pub.Listen(ch, newApp, fmt.Sprintf(":%d", httpPort))

	<-ch
}
示例#2
0
文件: daemon.go 项目: yonglehou/go2o
// 运行
func Run(ctx gof.App) {
	if ctx != nil {
		appCtx = ctx.(*core.MainApp)
	} else {
		appCtx = core.NewMainApp("app.conf")
	}
	_db = appCtx.Db()
	_orm = _db.GetOrm()
	sMail := appCtx.Config().GetString(variable.SystemMailQueueOff) != "1" //是否关闭系统邮件队列
	//sMail := cnf.GetString(variable.)

	s := &defaultService{
		sMember: true,
		sOrder:  true,
		sMail:   sMail,
	}
	s.init()
	Start()
}
示例#3
0
func main() {
	var (
		port      int
		ch        chan bool = make(chan bool)
		logOutput bool
		conf      string
	)

	flag.IntVar(&port, "port", 14197, "")
	flag.StringVar(&conf, "conf", "app.conf", "")
	flag.BoolVar(&logOutput, "l", false, "log output")
	flag.Parse()

	log.SetOutput(os.Stdout)
	log.SetFlags(log.LstdFlags | log.Ltime | log.Ldate | log.Lshortfile)

	gof.CurrentApp = core.NewMainApp(conf)
	dps.Init(gof.CurrentApp)
	cache.Initialize(gof.CurrentApp.Storage())
	fix.CustomFix()

	ts := tcpserve.NewServe(logOutput)
	ts.RegisterJob(tcpserve.MemberSummaryNotifyJob) //注册会员信息通知
	ts.RegisterJob(tcpserve.AccountNotifyJob)       //注册账户通知任务
	go ts.Listen(fmt.Sprintf(":%d", port))          //启动服务

	// 检测退出信号
	go func(mainCh chan bool) {
		ch := make(chan os.Signal)
		signal.Notify(ch, syscall.SIGTERM, syscall.SIGKILL)
		for {
			switch <-ch {
			case syscall.SIGKILL, syscall.SIGTERM:
				log.Println("[ Tcp][ Term] - tcp serve has term!")
				close(mainCh)
			}
		}
	}(ch)
	log.Println("[ TCP][ SERVE] - socket is serve on port :", port)
	<-ch
}
示例#4
0
文件: daemon.go 项目: yonglehou/go2o
// 自定义参数运行
func FlagRun() {
	var conf string
	var debug bool
	var trace bool
	var service string
	var serviceArr []string = []string{"mail", "order"}
	var ch chan bool = make(chan bool)
	flag.StringVar(&conf, "conf", "app.conf", "")
	flag.BoolVar(&debug, "debug", true, "")
	flag.BoolVar(&trace, "trace", true, "")
	flag.StringVar(&service, "service", strings.Join(serviceArr, ","), "")

	flag.Parse()

	appCtx = core.NewMainApp(conf)
	appCtx.Init(debug, trace)
	gof.CurrentApp = appCtx

	_db = appCtx.Db()
	_orm = _db.GetOrm()

	dps.Init(appCtx)

	//todo:???
	//	if service != "all" {
	//		serviceArr = strings.Split(service, ",")
	//	}
	// RegisterByName(serviceArr)

	s := &defaultService{
		sMember: true,
		sOrder:  true,
		sMail:   true,
	}
	s.init()
	Start()

	<-ch
}
示例#5
0
func main() {
	var (
		ch        chan bool = make(chan bool)
		confFile  string
		httpPort  int
		restPort  int
		debug     bool
		trace     bool
		runDaemon bool // 运行daemon
		help      bool
		newApp    *core.MainApp
	)

	flag.IntVar(&httpPort, "port", 14190, "web server port")
	flag.IntVar(&restPort, "restport", 14191, "rest api port")
	flag.BoolVar(&debug, "debug", false, "enable debug")
	flag.BoolVar(&trace, "trace", false, "enable trace")
	flag.BoolVar(&help, "help", false, "command usage")
	flag.StringVar(&confFile, "conf", "app.conf", "")
	flag.BoolVar(&runDaemon, "d", false, "run daemon")
	flag.Parse()

	if help {
		flag.Usage()
		return
	}

	log.SetOutput(os.Stdout)
	log.SetFlags(log.LstdFlags | log.Ltime | log.Ldate | log.Lshortfile)

	runtime.GOMAXPROCS(runtime.NumCPU())
	newApp = core.NewMainApp(confFile)
	if !newApp.Init(debug, trace) {
		os.Exit(1)
	}
	fix.CustomFix()
	go fix.SignalNotify(ch)

	if v := newApp.Config().GetInt("server_port"); v != 0 {
		httpPort = v
	}
	if v := newApp.Config().GetInt("api_service_port"); v != 0 {
		restPort = v
	}

	gof.CurrentApp = newApp
	dps.Init(newApp)
	cache.Initialize(storage.NewRedisStorage(newApp.Redis()))
	session.Set(newApp.Storage(), "")

	var booted bool

	if runDaemon {
		go daemon.Run(newApp)
	}

	go app.Run(ch, newApp, fmt.Sprintf(":%d", httpPort)) //运行HTTP

	go restapi.Run(newApp, restPort) // 运行REST API

	if booted {
		<-ch
	}

	os.Exit(1) // 退出
}