main.go 811 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/app-player/conf"
  8. "go-common/app/job/main/app-player/http"
  9. "go-common/library/log"
  10. )
  11. func main() {
  12. flag.Parse()
  13. if err := conf.Init(); err != nil {
  14. log.Error("conf.Init() error(%v)", err)
  15. panic(err)
  16. }
  17. log.Init(conf.Conf.XLog)
  18. defer log.Close()
  19. log.Info("app-player-job start")
  20. http.Init(conf.Conf)
  21. signalHandler()
  22. }
  23. func signalHandler() {
  24. var (
  25. ch = make(chan os.Signal, 1)
  26. )
  27. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  28. for {
  29. si := <-ch
  30. switch si {
  31. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  32. log.Info("get a signal %s, stop the consume process", si.String())
  33. http.Svc.Close()
  34. return
  35. case syscall.SIGHUP:
  36. default:
  37. return
  38. }
  39. }
  40. }