main.go 958 B

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