main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/main/push/conf"
  10. pushrpc "go-common/app/service/main/push/server/gorpc"
  11. "go-common/app/service/main/push/server/grpc"
  12. "go-common/app/service/main/push/server/http"
  13. "go-common/app/service/main/push/service"
  14. ecode "go-common/library/ecode/tip"
  15. "go-common/library/log"
  16. "go-common/library/net/trace"
  17. )
  18. func main() {
  19. flag.Parse()
  20. if err := conf.Init(); err != nil {
  21. log.Error("conf.Init() error(%v)", err)
  22. panic(err)
  23. }
  24. log.Init(conf.Conf.Log)
  25. trace.Init(conf.Conf.Tracer)
  26. defer trace.Close()
  27. defer log.Close()
  28. log.Info("push-service start")
  29. ecode.Init(conf.Conf.Ecode)
  30. svr := service.New(conf.Conf)
  31. rpcSrv := pushrpc.New(conf.Conf, svr)
  32. grpcSvr := grpc.New(conf.Conf.GRPC, svr)
  33. http.Init(conf.Conf, svr)
  34. c := make(chan os.Signal, 1)
  35. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  36. for {
  37. s := <-c
  38. log.Info("push-service get a signal %s", s.String())
  39. switch s {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  41. rpcSrv.Close()
  42. grpcSvr.Shutdown(context.Background())
  43. svr.Close()
  44. log.Info("push-service exit")
  45. time.Sleep(time.Second)
  46. return
  47. case syscall.SIGHUP:
  48. default:
  49. return
  50. }
  51. }
  52. }