main.go 948 B

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