main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "context"
  9. "go-common/app/service/main/relation/conf"
  10. "go-common/app/service/main/relation/http"
  11. "go-common/app/service/main/relation/rpc/server"
  12. "go-common/app/service/main/relation/server/grpc"
  13. "go-common/app/service/main/relation/service"
  14. "go-common/library/log"
  15. "go-common/library/net/trace"
  16. "go-common/library/queue/databus/report"
  17. )
  18. func main() {
  19. flag.Parse()
  20. // init conf,log,trace,stat,perf.
  21. if err := conf.Init(); err != nil {
  22. panic(err)
  23. }
  24. log.Init(conf.Conf.Log)
  25. defer log.Close()
  26. trace.Init(conf.Conf.Tracer)
  27. defer trace.Close()
  28. // report
  29. report.InitUser(conf.Conf.Report)
  30. // service init WardenServer *warden.ServerConfig
  31. svr := service.New(conf.Conf)
  32. rpcSvr := rpc.New(conf.Conf, svr)
  33. //start grpc
  34. ws := grpc.New(conf.Conf, svr)
  35. http.Init(conf.Conf, svr)
  36. // signal handler
  37. log.Info("relation-service start")
  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("relation-service get a signal %s", s.String())
  43. switch s {
  44. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  45. ws.Shutdown(context.Background())
  46. rpcSvr.Close()
  47. time.Sleep(time.Second * 2)
  48. log.Info("relation-service exit")
  49. return
  50. case syscall.SIGHUP:
  51. default:
  52. return
  53. }
  54. }
  55. }