main.go 1.2 KB

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