main.go 1.4 KB

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