main.go 978 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/credit-timer/conf"
  8. "go-common/app/job/main/credit-timer/http"
  9. "go-common/app/job/main/credit-timer/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(conf.Conf.Xlog)
  22. defer log.Close()
  23. log.Info("credit-timer start")
  24. http.Init(conf.Conf)
  25. signalHandler()
  26. }
  27. func signalHandler() {
  28. var (
  29. err error
  30. ch = make(chan os.Signal, 1)
  31. )
  32. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  33. for {
  34. si := <-ch
  35. switch si {
  36. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  37. log.Info("get a signal %s, stop the consume process", si.String())
  38. if err = srv.Close(); err != nil {
  39. log.Error("srv close consumer error(%v)", err)
  40. }
  41. return
  42. case syscall.SIGHUP:
  43. default:
  44. return
  45. }
  46. }
  47. }