46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"samba/pkg/log"
|
|
"samba/pkg/servername"
|
|
"samba/server/cacheta/handler"
|
|
. "samba/server/cacheta/service"
|
|
"samba/util/config"
|
|
"samba/util/model"
|
|
"syscall"
|
|
)
|
|
|
|
func initLog(command *config.Command) {
|
|
log.Open(fmt.Sprintf("%v/%v/%v.log", command.LogPath, servername.Cacheta, QueueName()), 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))
|
|
}
|