mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 04:02:29 +02:00
Graceful shut down server and vips
This commit is contained in:
15
main.go
15
main.go
@@ -4,6 +4,8 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
@@ -29,7 +31,16 @@ func main() {
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
}
|
||||
|
||||
log.Printf("Starting server at %s\n", conf.Bind)
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, os.Interrupt, os.Kill)
|
||||
|
||||
log.Fatal(s.Serve(netutil.LimitListener(l, conf.MaxClients)))
|
||||
go func() {
|
||||
log.Printf("Starting server at %s\n", conf.Bind)
|
||||
log.Fatal(s.Serve(netutil.LimitListener(l, conf.MaxClients)))
|
||||
}()
|
||||
|
||||
<-stop
|
||||
|
||||
shutdownVips()
|
||||
shutdownServer(s)
|
||||
}
|
||||
|
@@ -127,6 +127,10 @@ func initVips() {
|
||||
}
|
||||
}
|
||||
|
||||
func shutdownVips() {
|
||||
C.vips_shutdown()
|
||||
}
|
||||
|
||||
func randomAccessRequired(po processingOptions) int {
|
||||
if po.gravity == SMART {
|
||||
return 1
|
||||
|
19
shutdown.go
Normal file
19
shutdown.go
Normal file
@@ -0,0 +1,19 @@
|
||||
// +build go1.8
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func shutdownServer(s *http.Server) {
|
||||
log.Println("Shutting down the server...")
|
||||
|
||||
ctx, close := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer close()
|
||||
|
||||
s.Shutdown(ctx)
|
||||
}
|
11
shutdown_old.go
Normal file
11
shutdown_old.go
Normal file
@@ -0,0 +1,11 @@
|
||||
// +build !go1.8
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func shutdownServer(_ *http.Server) {
|
||||
// Nothing we can do here
|
||||
}
|
Reference in New Issue
Block a user