main.go 974 B

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