main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/service/bbq/recsys-recall/conf"
  8. "go-common/app/service/bbq/recsys-recall/server/grpc"
  9. "go-common/app/service/bbq/recsys-recall/server/http"
  10. "go-common/app/service/bbq/recsys-recall/service"
  11. "go-common/app/service/bbq/recsys-recall/service/index"
  12. ecode "go-common/library/ecode/tip"
  13. "go-common/library/log"
  14. "go-common/library/net/trace"
  15. )
  16. func main() {
  17. // cpuf, err := os.Create("cpu_profile")
  18. // if err != nil {
  19. // panic(err)
  20. // }
  21. // pprof.StartCPUProfile(cpuf)
  22. // defer pprof.StopCPUProfile()
  23. flag.Parse()
  24. if err := conf.Init(); err != nil {
  25. panic(err)
  26. }
  27. log.Init(conf.Conf.Log)
  28. defer log.Close()
  29. log.Info("start")
  30. trace.Init(conf.Conf.Tracer)
  31. defer trace.Close()
  32. ecode.Init(conf.Conf.Ecode)
  33. srv := service.New(conf.Conf)
  34. // 加载正排索引
  35. index.Init(conf.Conf)
  36. grpc.New(srv)
  37. http.Init(conf.Conf)
  38. c := make(chan os.Signal, 1)
  39. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  40. for {
  41. s := <-c
  42. log.Info("get a signal %s", s.String())
  43. switch s {
  44. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  45. log.Info("exit")
  46. return
  47. case syscall.SIGHUP:
  48. default:
  49. return
  50. }
  51. }
  52. }