main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "time"
  6. "go-common/app/admin/main/appstatic/conf"
  7. "go-common/app/admin/main/appstatic/http"
  8. "go-common/app/admin/main/appstatic/service"
  9. "go-common/library/log"
  10. "go-common/library/net/trace"
  11. "go-common/library/os/signal"
  12. "go-common/library/syscall"
  13. )
  14. var (
  15. s *service.Service
  16. )
  17. func main() {
  18. flag.Parse()
  19. if err := conf.Init(); err != nil {
  20. log.Error("conf.Init() error(%v)", err)
  21. panic(err)
  22. }
  23. log.Init(conf.Conf.XLog)
  24. defer log.Close()
  25. trace.Init(conf.Conf.Tracer)
  26. defer trace.Close()
  27. // service init
  28. s = service.New(conf.Conf)
  29. http.Init(conf.Conf, s)
  30. log.Info("appstatic-admin start")
  31. signalHandler()
  32. }
  33. func signalHandler() {
  34. var (
  35. ch = make(chan os.Signal, 1)
  36. )
  37. signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT, syscall.SIGSTOP)
  38. for {
  39. si := <-ch
  40. switch si {
  41. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  42. time.Sleep(time.Second * 2)
  43. log.Info("get a signal %s, stop the appstatic-admin process", si.String())
  44. s.Wait()
  45. s.Close()
  46. time.Sleep(time.Second)
  47. return
  48. case syscall.SIGHUP:
  49. default:
  50. return
  51. }
  52. }
  53. }