main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/main/archive/conf"
  10. rpc "go-common/app/service/main/archive/server/gorpc"
  11. "go-common/app/service/main/archive/server/grpc"
  12. "go-common/app/service/main/archive/server/http"
  13. "go-common/app/service/main/archive/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. // init ecode
  25. ecode.Init(nil)
  26. // init log
  27. log.Init(conf.Conf.Xlog)
  28. trace.Init(conf.Conf.Tracer)
  29. defer trace.Close()
  30. defer log.Close()
  31. log.Info("archive-service start")
  32. // service init
  33. svr := service.New(conf.Conf)
  34. // statsd init
  35. rpcSvr := rpc.New(conf.Conf, svr)
  36. grpcSvr, err := grpc.New(nil, svr)
  37. if err != nil {
  38. panic(err)
  39. }
  40. http.Init(conf.Conf, svr)
  41. // init signal
  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("archive-service get a signal %s", s.String())
  47. switch s {
  48. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  49. rpcSvr.Close()
  50. grpcSvr.Shutdown(context.TODO())
  51. time.Sleep(time.Second * 2)
  52. log.Info("archive-service exit")
  53. return
  54. case syscall.SIGHUP:
  55. // TODO reload
  56. default:
  57. return
  58. }
  59. }
  60. }