1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2024-11-24 08:12:38 +02:00
imgproxy/main.go
2019-08-09 16:12:36 +06:00

56 lines
897 B
Go

package main
import (
"log"
"os"
"os/signal"
"runtime"
"runtime/debug"
"syscall"
"time"
)
const version = "2.3.0"
type ctxKey string
func initialize() {
log.SetOutput(os.Stdout)
initSyslog()
configure()
initNewrelic()
initPrometheus()
initDownloading()
initErrorsReporting()
initVips()
}
func main() {
initialize()
go func() {
var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0
for range time.Tick(time.Duration(conf.FreeMemoryInterval) * time.Second) {
debug.FreeOSMemory()
if logMemStats {
var m runtime.MemStats
runtime.ReadMemStats(&m)
logNotice("[MEMORY USAGE] Sys: %d; HeapIdle: %d; HeapInuse: %d", m.Sys/1024/1024, m.HeapIdle/1024/1024, m.HeapInuse/1024/1024)
}
}
}()
s := startServer()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
<-stop
shutdownServer(s)
shutdownVips()
}