samba/server/hall/cmd/cmd.go

45 lines
1021 B
Go
Raw Normal View History

2025-06-04 09:51:39 +08:00
package cmd
import (
"fmt"
"os"
"os/signal"
"samba/pkg/log"
"samba/pkg/servername"
"samba/server/hall/handler"
"samba/util/config"
"samba/util/model"
"syscall"
)
func initLog(command *config.Command) {
log.Open(fmt.Sprintf("%v/%v/%v.log", command.LogPath, servername.Hall, servername.Hall), command.LogLevel)
}
func initRepo() {
model.InitUserDB(&config.Config.DBConfig)
model.InitConfigDB(&config.Config.DBConfig)
model.InitRedis(&config.Config.Redis)
model.InitStub()
//_ = model.InitRobot()
}
func Run(version string) {
command := config.ParseCommand()
initLog(command)
log.Info(fmt.Sprintf("版本信息.%v", version))
var 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...\n", sig))
}