main.go 1.1 KB

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