main.go 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/coin/conf"
  8. "go-common/app/job/main/coin/http"
  9. "go-common/app/job/main/coin/service"
  10. "go-common/library/log"
  11. )
  12. var (
  13. s *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("archive-service_consumer start")
  24. s = service.New(conf.Conf)
  25. http.Init(conf.Conf, s)
  26. signalHandler()
  27. }
  28. func signalHandler() {
  29. ch := make(chan os.Signal, 1)
  30. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  31. for {
  32. si := <-ch
  33. switch si {
  34. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  35. log.Info("get a signal %s, stop the consume process", si.String())
  36. s.Close()
  37. s.Wait()
  38. return
  39. case syscall.SIGHUP:
  40. default:
  41. return
  42. }
  43. }
  44. }