main.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/member/conf"
  8. "go-common/app/job/main/member/http"
  9. "go-common/app/job/main/member/service"
  10. "go-common/library/log"
  11. "go-common/library/queue/databus/report"
  12. )
  13. var (
  14. svr *service.Service
  15. )
  16. func main() {
  17. flag.Parse()
  18. if err := conf.Init(); err != nil {
  19. log.Error("conf.Init() error(%v)", err)
  20. panic(err)
  21. }
  22. log.Init(conf.Conf.Xlog)
  23. defer log.Close()
  24. report.InitUser(conf.Conf.UserReport)
  25. report.InitManager(conf.Conf.ManagerReport)
  26. log.Info("member-job start")
  27. svr = service.New(conf.Conf)
  28. http.Init(conf.Conf, svr)
  29. signalHandler()
  30. }
  31. func signalHandler() {
  32. var (
  33. err error
  34. ch = make(chan os.Signal, 1)
  35. )
  36. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  37. for {
  38. si := <-ch
  39. switch si {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  41. log.Info("get a signal %s, stop the consume process", si.String())
  42. if err = svr.Close(); err != nil {
  43. log.Error("srv close consumer error(%v)", err)
  44. }
  45. return
  46. case syscall.SIGHUP:
  47. default:
  48. return
  49. }
  50. }
  51. }