main.go 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/job/main/creative/conf"
  9. "go-common/app/job/main/creative/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. log.Error("conf.Init() error(%v)", err)
  17. panic(err)
  18. }
  19. // init log
  20. log.Init(conf.Conf.Log)
  21. trace.Init(conf.Conf.Tracer)
  22. defer trace.Close()
  23. defer log.Close()
  24. log.Info("creative-jobstart")
  25. // service init
  26. http.Init(conf.Conf)
  27. // init signal
  28. c := make(chan os.Signal, 1)
  29. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  30. for {
  31. s := <-c
  32. log.Info("creative-job get a signal %s", s.String())
  33. switch s {
  34. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  35. http.Svc.Close()
  36. log.Info("creative-jobexit")
  37. time.Sleep(1 * time.Second)
  38. return
  39. case syscall.SIGHUP:
  40. // TODO reload
  41. default:
  42. return
  43. }
  44. }
  45. }