main.go 1.2 KB

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