44 lines
1021 B
Go
Raw Permalink 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/other/handler"
"samba/util/config"
"samba/util/model"
"syscall"
)
func initLog(command *config.Command) {
log.Open(fmt.Sprintf("%v/%v/%v.log", command.LogPath, servername.Other, servername.Other), command.LogLevel)
}
func initRepo() {
model.InitRedis(&config.Config.Redis)
model.InitUserDB(&config.Config.DBConfig)
model.InitPayDB(&config.Config.DBConfig)
model.InitDataDB(&config.Config.DBConfig)
}
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))
}