main.go 999 B

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