main.go 887 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.5.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. }
  23. func main() {
  24. initialize()
  25. go func() {
  26. var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0
  27. for range time.Tick(time.Duration(conf.FreeMemoryInterval) * time.Second) {
  28. debug.FreeOSMemory()
  29. if logMemStats {
  30. var m runtime.MemStats
  31. runtime.ReadMemStats(&m)
  32. logDebug("MEMORY USAGE: Sys=%d HeapIdle=%d HeapInuse=%d", m.Sys/1024/1024, m.HeapIdle/1024/1024, m.HeapInuse/1024/1024)
  33. }
  34. }
  35. }()
  36. s := startServer()
  37. stop := make(chan os.Signal, 1)
  38. signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
  39. <-stop
  40. shutdownServer(s)
  41. shutdownVips()
  42. }