2017-06-20 15:58:55 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-10-17 14:23:48 +02:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2019-01-17 10:51:19 +02:00
|
|
|
"runtime"
|
|
|
|
"runtime/debug"
|
2019-04-11 16:07:09 +02:00
|
|
|
"syscall"
|
2019-01-17 10:51:19 +02:00
|
|
|
"time"
|
2017-06-20 15:58:55 +02:00
|
|
|
)
|
|
|
|
|
2019-05-07 13:55:15 +02:00
|
|
|
const version = "2.2.13"
|
2018-09-06 15:02:21 +02:00
|
|
|
|
2018-10-05 17:17:36 +02:00
|
|
|
type ctxKey string
|
|
|
|
|
2019-06-06 15:26:00 +02:00
|
|
|
func initialize() {
|
|
|
|
initSyslog()
|
|
|
|
configure()
|
|
|
|
initNewrelic()
|
|
|
|
initPrometheus()
|
|
|
|
initDownloading()
|
|
|
|
initErrorsReporting()
|
|
|
|
initVips()
|
|
|
|
}
|
|
|
|
|
2017-06-20 15:58:55 +02:00
|
|
|
func main() {
|
2019-06-06 15:26:00 +02:00
|
|
|
initialize()
|
|
|
|
|
2019-01-17 10:51:19 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-09-10 08:17:00 +02:00
|
|
|
s := startServer()
|
2017-06-20 15:58:55 +02:00
|
|
|
|
2017-10-17 14:23:48 +02:00
|
|
|
stop := make(chan os.Signal, 1)
|
2019-04-11 16:07:09 +02:00
|
|
|
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
2017-06-20 15:58:55 +02:00
|
|
|
|
2017-10-17 14:23:48 +02:00
|
|
|
<-stop
|
|
|
|
|
|
|
|
shutdownServer(s)
|
2018-09-10 08:17:00 +02:00
|
|
|
shutdownVips()
|
2017-06-20 15:58:55 +02:00
|
|
|
}
|