main.go 1.1 KB

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