main.go 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/up/conf"
  8. "go-common/app/job/main/up/server/http"
  9. ecode "go-common/library/ecode/tip"
  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. log.SetFormat("[%D %T] [%L] [%S] %M")
  20. defer log.Close()
  21. log.Info("server start")
  22. trace.Init(conf.Conf.Tracer)
  23. defer trace.Close()
  24. ecode.Init(conf.Conf.Ecode)
  25. http.Init(conf.Conf)
  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. log.Info("[server] exit")
  34. return
  35. case syscall.SIGHUP:
  36. default:
  37. return
  38. }
  39. }
  40. }