main.go 931 B

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