package cmd import ( "fmt" "os" "os/signal" "samba/pkg/log" "samba/pkg/servername" . "samba/server/game/player" "samba/server/truco/handler" . "samba/server/truco/service" "samba/util/config" "samba/util/model" "syscall" ) func initLog(command *config.Command) { log.Open(fmt.Sprintf("%v/%v/%v.log", command.LogPath, servername.Truco, QueueName()), command.LogLevel) } func initRepo() { model.InitUserDB(&config.Config.DBConfig) model.InitConfigDB(&config.Config.DBConfig) model.InitRedis(&config.Config.Redis) model.InitStub() RobotMgr.Load() ClubRobotMgr.Load() //log.Debug(fmt.Sprintf("%+v", stub.GGlobal)) } func Run(version string) { command := config.ParseCommand() initLog(command) log.Info(fmt.Sprintf("版本信息.%v", version)) err := config.Load(command.ConfigPath) if err != nil { log.Error(fmt.Sprintf("load config err: %v", err)) } initRepo() handler.InitService() // 截获 SIGINT 和 SIGTERM 信号 c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) sig := <-c handler.StopService() log.Info(fmt.Sprintf("received %s, initiating shutdown...", sig)) }