gracefull shutdown
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
9981373b83
commit
5089535fce
1 changed files with 16 additions and 2 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
|
|
@ -54,7 +55,20 @@ var serveCmd = &cobra.Command{
|
|||
syncSvc.StartScheduler(ctx, cfg.Sync.IntervalDuration())
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
||||
srv := &http.Server{Addr: addr, Handler: router}
|
||||
|
||||
go func() {
|
||||
log.Printf("ClonePack listening on %s", addr)
|
||||
return http.ListenAndServe(addr, router)
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Printf("server error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
<-ctx.Done()
|
||||
log.Printf("shutting down...")
|
||||
|
||||
shutdownCtx, cancel2 := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel2()
|
||||
return srv.Shutdown(shutdownCtx)
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue