main.go 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "go-common/app/service/main/share/conf"
  9. "go-common/app/service/main/share/server/grpc"
  10. "go-common/app/service/main/share/server/http"
  11. "go-common/app/service/main/share/service"
  12. "go-common/library/log"
  13. )
  14. func main() {
  15. flag.Parse()
  16. if err := conf.Init(); err != nil {
  17. log.Error("conf.Init() error(%v)", err)
  18. panic(err)
  19. }
  20. // init log
  21. log.Init(conf.Conf.Xlog)
  22. defer log.Close()
  23. log.Info("share-service start")
  24. svr := service.New(conf.Conf)
  25. grpcSvr := grpc.New(conf.Conf.WardenServer, svr)
  26. http.Init(conf.Conf, svr)
  27. c := make(chan os.Signal, 1)
  28. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  29. for {
  30. s := <-c
  31. log.Info("share-service get a signal %s", s.String())
  32. switch s {
  33. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  34. grpcSvr.Shutdown(context.Background())
  35. log.Info("share-service exit")
  36. return
  37. case syscall.SIGHUP:
  38. default:
  39. return
  40. }
  41. }
  42. }