main.go 845 B

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