main.go 1.1 KB

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