main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/service/main/search/conf"
  9. "go-common/app/service/main/search/http"
  10. "go-common/app/service/main/search/service"
  11. "go-common/library/log"
  12. "go-common/library/net/trace"
  13. )
  14. func main() {
  15. flag.Parse()
  16. // init conf,log,trace,stat,perf.
  17. if err := conf.Init(); err != nil {
  18. panic(err)
  19. }
  20. log.Init(conf.Conf.Xlog)
  21. defer log.Close()
  22. trace.Init(conf.Conf.Tracer)
  23. defer trace.Close()
  24. // service init
  25. svr := service.New(conf.Conf)
  26. http.Init(conf.Conf, svr)
  27. // signal handler
  28. log.Info("search-interface start")
  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("search-interface get a signal %s", s.String())
  34. switch s {
  35. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  36. time.Sleep(time.Second * 2)
  37. log.Info("search-interface exit")
  38. return
  39. case syscall.SIGHUP:
  40. // TODO reload
  41. default:
  42. return
  43. }
  44. }
  45. }