main.go 1.1 KB

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