main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/archive-shjd/conf"
  8. "go-common/app/job/main/archive-shjd/http"
  9. "go-common/app/job/main/archive-shjd/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. // init log
  22. log.Init(conf.Conf.Log)
  23. defer log.Close()
  24. log.Info("archive-kisjd-job start")
  25. srv = service.New(conf.Conf)
  26. http.Init(conf.Conf, srv)
  27. signalHandler()
  28. }
  29. func signalHandler() {
  30. var (
  31. err error
  32. ch = make(chan os.Signal, 1)
  33. )
  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. if err = srv.Close(); err != nil {
  41. log.Error("srv close consumer error(%v)", err)
  42. }
  43. return
  44. case syscall.SIGHUP:
  45. default:
  46. return
  47. }
  48. }
  49. }