main.go 878 B

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