1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-23 11:14:48 +02:00
imgproxy/main.go

63 lines
1.0 KiB
Go
Raw Normal View History

2017-06-20 16:58:55 +03:00
package main
import (
2019-08-09 16:12:04 +06:00
"log"
2017-10-17 18:23:48 +06:00
"os"
"os/signal"
"runtime"
"syscall"
"time"
2017-06-20 16:58:55 +03:00
)
2020-01-30 22:06:33 +06:00
const version = "2.9.0"
2018-10-05 21:17:36 +06:00
type ctxKey string
2019-06-06 19:26:00 +06:00
func initialize() {
2019-08-09 16:12:04 +06:00
log.SetOutput(os.Stdout)
initLog()
2019-06-06 19:26:00 +06:00
configure()
initNewrelic()
initPrometheus()
initDownloading()
initErrorsReporting()
initVips()
2019-11-11 17:54:46 +06:00
if err := checkPresets(conf.Presets); err != nil {
shutdownVips()
logFatal(err.Error())
}
2019-06-06 19:26:00 +06:00
}
2017-06-20 16:58:55 +03:00
func main() {
2020-02-04 17:48:33 +06:00
if len(os.Args) > 1 && os.Args[1] == "health" {
healthcheck()
}
2019-06-06 19:26:00 +06:00
initialize()
2020-02-04 16:18:09 +06:00
defer shutdownVips()
2019-06-06 19:26:00 +06:00
go func() {
var logMemStats = len(os.Getenv("IMGPROXY_LOG_MEM_STATS")) > 0
for range time.Tick(time.Duration(conf.FreeMemoryInterval) * time.Second) {
2020-01-10 20:52:40 +06:00
freeMemory()
if logMemStats {
var m runtime.MemStats
runtime.ReadMemStats(&m)
logDebug("MEMORY USAGE: Sys=%d HeapIdle=%d HeapInuse=%d", m.Sys/1024/1024, m.HeapIdle/1024/1024, m.HeapInuse/1024/1024)
}
}
}()
2018-09-10 12:17:00 +06:00
s := startServer()
2020-02-04 16:18:09 +06:00
defer shutdownServer(s)
2017-06-20 16:58:55 +03:00
2017-10-17 18:23:48 +06:00
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
2017-06-20 16:58:55 +03:00
2017-10-17 18:23:48 +06:00
<-stop
2017-06-20 16:58:55 +03:00
}