main.go 1005 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/admin/main/workflow/http"
  9. "go-common/app/admin/main/workflow/service"
  10. "go-common/library/conf/paladin"
  11. ecode "go-common/library/ecode/tip"
  12. "go-common/library/log"
  13. "go-common/library/queue/databus/report"
  14. )
  15. func main() {
  16. flag.Parse()
  17. if err := paladin.Init(); err != nil {
  18. panic(err)
  19. }
  20. // init log
  21. log.Init(nil)
  22. defer log.Close()
  23. log.Info("workflow-admin start")
  24. svc := service.New()
  25. http.Init(svc)
  26. // report
  27. report.InitManager(nil)
  28. // ecode init
  29. ecode.Init(nil)
  30. // init signal
  31. c := make(chan os.Signal, 1)
  32. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  33. for {
  34. s := <-c
  35. log.Info("workflow-admin get a signal %s", s.String())
  36. switch s {
  37. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  38. log.Info("workflow-admin exit")
  39. time.Sleep(1 * time.Second)
  40. svc.Close()
  41. return
  42. case syscall.SIGHUP:
  43. // TODO reload
  44. default:
  45. return
  46. }
  47. }
  48. }