main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/main/sms/conf"
  10. gorpc "go-common/app/service/main/sms/server/gorpc"
  11. grpc "go-common/app/service/main/sms/server/grpc"
  12. "go-common/app/service/main/sms/server/http"
  13. "go-common/app/service/main/sms/service"
  14. "go-common/library/log"
  15. "go-common/library/net/trace"
  16. )
  17. func main() {
  18. flag.Parse()
  19. if err := conf.Init(); err != nil {
  20. panic(err)
  21. }
  22. log.Init(conf.Conf.Xlog)
  23. defer log.Close()
  24. trace.Init(conf.Conf.Tracer)
  25. defer trace.Close()
  26. svr := service.New(conf.Conf)
  27. gorpcSvr := gorpc.New(conf.Conf, svr)
  28. grpcSvr := grpc.New(conf.Conf.GRPC, svr)
  29. http.Init(conf.Conf, svr)
  30. log.Info("sms-service start")
  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("sms-service get a signal %s", s.String())
  36. switch s {
  37. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  38. gorpcSvr.Close()
  39. grpcSvr.Shutdown(context.Background())
  40. svr.Close()
  41. time.Sleep(time.Second * 2)
  42. log.Info("sms-service exit")
  43. return
  44. case syscall.SIGHUP:
  45. // TODO reload
  46. default:
  47. return
  48. }
  49. }
  50. }