main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/service/main/push-strategy/conf"
  9. "go-common/app/service/main/push-strategy/http"
  10. "go-common/app/service/main/push-strategy/service"
  11. ecode "go-common/library/ecode/tip"
  12. "go-common/library/log"
  13. "go-common/library/net/trace"
  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.Log)
  22. defer log.Close()
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. log.Info("push-strategystart")
  26. ecode.Init(conf.Conf.Ecode)
  27. srv := service.New(conf.Conf)
  28. http.Init(conf.Conf, srv)
  29. c := make(chan os.Signal, 1)
  30. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  31. for {
  32. s := <-c
  33. log.Info("push-strategy get a signal %s", s.String())
  34. switch s {
  35. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  36. srv.Close()
  37. time.Sleep(1 * time.Second)
  38. log.Info("push-strategyexit")
  39. return
  40. case syscall.SIGHUP:
  41. // TODO reload
  42. default:
  43. return
  44. }
  45. }
  46. }