main.go 1.1 KB

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