main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "time"
  7. "go-common/app/admin/main/videoup-task/conf"
  8. "go-common/app/admin/main/videoup-task/http"
  9. "go-common/app/admin/main/videoup-task/service"
  10. "go-common/library/log"
  11. "go-common/library/net/trace"
  12. "go-common/library/os/signal"
  13. "go-common/library/queue/databus/report"
  14. "go-common/library/syscall"
  15. )
  16. func main() {
  17. var err error
  18. //conf init
  19. flag.Parse()
  20. if err = conf.Init(); err != nil {
  21. panic(err)
  22. }
  23. //log init
  24. log.Init(conf.Conf.Xlog)
  25. defer log.Close()
  26. fmt.Printf("conf(%+v)", conf.Conf)
  27. report.InitManager(conf.Conf.ManagerReport)
  28. //trace init
  29. trace.Init(nil)
  30. defer trace.Close()
  31. //http init
  32. srv := service.New(conf.Conf)
  33. http.Init(conf.Conf, srv)
  34. //signal notify to change service behavior
  35. sch := make(chan os.Signal, 1)
  36. signal.Notify(sch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  37. for {
  38. s := <-sch
  39. log.Info("videoup-task-admin got a signal %s", s.String())
  40. switch s {
  41. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  42. log.Info("videoup-task-admin is closed")
  43. srv.Close()
  44. time.Sleep(time.Second * 1)
  45. return
  46. case syscall.SIGHUP:
  47. //reload
  48. default:
  49. return
  50. }
  51. }
  52. }