main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/service/main/passport/conf"
  9. "go-common/app/service/main/passport/http"
  10. rpc "go-common/app/service/main/passport/rpc/server"
  11. "go-common/app/service/main/passport/service"
  12. "go-common/library/log"
  13. xrpc "go-common/library/net/rpc"
  14. "go-common/library/net/trace"
  15. )
  16. func main() {
  17. flag.Parse()
  18. // init conf,log,trace,stat,perf.
  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. // service init
  27. svr := service.New(conf.Conf)
  28. var rpcSvr *xrpc.Server
  29. if conf.Conf.Switch.RPC {
  30. rpcSvr = rpc.New(conf.Conf, svr)
  31. }
  32. http.Init(conf.Conf, svr)
  33. // signal handler
  34. log.Info("passport-service start")
  35. c := make(chan os.Signal, 1)
  36. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  37. for {
  38. s := <-c
  39. log.Info("passport-service get a signal %s", s.String())
  40. switch s {
  41. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  42. log.Info("passport-service exit")
  43. if conf.Conf.Switch.RPC {
  44. rpcSvr.Close()
  45. time.Sleep(time.Second * 2)
  46. }
  47. svr.Close()
  48. return
  49. case syscall.SIGHUP:
  50. // TODO reload
  51. default:
  52. return
  53. }
  54. }
  55. }