main.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/main/identify/conf"
  10. "go-common/app/service/main/identify/server/grpc"
  11. "go-common/app/service/main/identify/server/http"
  12. "go-common/app/service/main/identify/service"
  13. "go-common/library/log"
  14. // "go-common/library/net/rpc/warden/resolver/livezk"
  15. "go-common/library/net/trace"
  16. )
  17. const (
  18. // discoveryID = "passport.service.identify"
  19. )
  20. func main() {
  21. flag.Parse()
  22. // init conf,log,trace,stat,perf.
  23. if err := conf.Init(); err != nil {
  24. panic(err)
  25. }
  26. log.Init(conf.Conf.Xlog)
  27. defer log.Close()
  28. trace.Init(conf.Conf.Tracer)
  29. defer trace.Close()
  30. // service init
  31. svr := service.New(conf.Conf)
  32. http.Init(conf.Conf, svr)
  33. // init warden server
  34. ws := grpc.New(conf.Conf.WardenServer, svr)
  35. // 先主站内部和chenzhihui测试可用,再对外提供
  36. // cancel, err := livezk.Register(conf.Conf.LiveZK, conf.Conf.WardenServer.Addr, discoveryID)
  37. // if err != nil {
  38. // panic(err)
  39. // }
  40. // signal handler
  41. log.Info("identify-service start")
  42. c := make(chan os.Signal, 1)
  43. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  44. for {
  45. s := <-c
  46. log.Info("identify-service get a signal %s", s.String())
  47. switch s {
  48. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  49. // cancel()
  50. ws.Shutdown(context.Background())
  51. time.Sleep(time.Second * 2)
  52. svr.Close()
  53. log.Info("identify-service exit")
  54. return
  55. case syscall.SIGHUP:
  56. // TODO reload
  57. default:
  58. return
  59. }
  60. }
  61. }