main.go 1.1 KB

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