main.go 864 B

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