main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/openplatform/article/conf"
  8. "go-common/app/job/openplatform/article/http"
  9. "go-common/app/job/openplatform/article/service"
  10. "go-common/library/log"
  11. "go-common/library/net/trace"
  12. )
  13. func main() {
  14. flag.Parse()
  15. initConf()
  16. initLog()
  17. defer log.Close()
  18. log.Info("article-job start")
  19. srv := service.New(conf.Conf)
  20. http.Init(conf.Conf, srv)
  21. initSignal(srv)
  22. }
  23. func initConf() {
  24. if err := conf.Init(); err != nil {
  25. panic(err)
  26. }
  27. }
  28. func initLog() {
  29. log.Init(conf.Conf.Xlog)
  30. trace.Init(conf.Conf.Tracer)
  31. defer trace.Close()
  32. }
  33. func initSignal(srv *service.Service) {
  34. c := make(chan os.Signal, 1)
  35. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  36. for {
  37. s := <-c
  38. log.Info("article-job get a signal: %s", s.String())
  39. switch s {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  41. if err := srv.Close(); err != nil {
  42. log.Error("srv close consumer error(%+v)", err)
  43. }
  44. return
  45. case syscall.SIGHUP:
  46. // TODO: reload
  47. default:
  48. return
  49. }
  50. }
  51. }