main.go 974 B

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