main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/service/openplatform/ticket-sales/conf"
  9. "go-common/app/service/openplatform/ticket-sales/server/grpc"
  10. "go-common/app/service/openplatform/ticket-sales/server/http"
  11. "go-common/app/service/openplatform/ticket-sales/service"
  12. "go-common/app/service/openplatform/ticket-sales/service/mis"
  13. "go-common/library/conf/paladin"
  14. ecode "go-common/library/ecode/tip"
  15. "go-common/library/log"
  16. "go-common/library/net/trace"
  17. )
  18. func main() {
  19. flag.Parse()
  20. if err := paladin.Init(); err != nil {
  21. panic(err)
  22. }
  23. if err := paladin.Watch("ticket-sales.toml", conf.Conf); err != nil {
  24. panic(err)
  25. }
  26. log.Init(conf.Conf.Log)
  27. defer log.Close()
  28. trace.Init(conf.Conf.Tracer)
  29. defer trace.Close()
  30. log.Info("ticket-sales start")
  31. ecode.Init(nil)
  32. // service init
  33. srv := service.New(conf.Conf)
  34. misSrv := mis.New(srv.Get())
  35. grpc.New(srv, misSrv)
  36. http.Init(conf.Conf, srv)
  37. log.Info("ready to serv")
  38. // signal handler
  39. c := make(chan os.Signal, 1)
  40. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  41. for {
  42. s := <-c
  43. log.Info("ticket-sales get a signal %s", s.String())
  44. switch s {
  45. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  46. // rpcSvr.Close()
  47. time.Sleep(time.Second * 2)
  48. log.Info("ticket-sales exit")
  49. return
  50. case syscall.SIGHUP:
  51. // TODO reload
  52. default:
  53. return
  54. }
  55. }
  56. }