main.go 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "log"
  4. "os"
  5. "os/signal"
  6. "runtime"
  7. "runtime/debug"
  8. "syscall"
  9. "time"
  10. )
  11. const version = "2.7.0"
  12. type ctxKey string
  13. func initialize() {
  14. log.SetOutput(os.Stdout)
  15. initLog()
  16. configure()
  17. initNewrelic()
  18. initPrometheus()
  19. initDownloading()
  20. initErrorsReporting()
  21. initVips()
  22. if err := checkPresets(conf.Presets); err != nil {
  23. shutdownVips()
  24. logFatal(err.Error())
  25. }
  26. }
  27. func main() {
  28. initialize()
  29. go func() {
  30. var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0
  31. for range time.Tick(time.Duration(conf.FreeMemoryInterval) * time.Second) {
  32. debug.FreeOSMemory()
  33. if logMemStats {
  34. var m runtime.MemStats
  35. runtime.ReadMemStats(&m)
  36. logDebug("MEMORY USAGE: Sys=%d HeapIdle=%d HeapInuse=%d", m.Sys/1024/1024, m.HeapIdle/1024/1024, m.HeapInuse/1024/1024)
  37. }
  38. }
  39. }()
  40. s := startServer()
  41. stop := make(chan os.Signal, 1)
  42. signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
  43. <-stop
  44. shutdownServer(s)
  45. shutdownVips()
  46. }