main.go 1017 B

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