2023-03-08 15:30:40 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func createSigChannel() (chan os.Signal, func()) {
|
|
|
|
signalCh := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
|
|
|
|
|
|
|
|
return signalCh, func() {
|
|
|
|
close(signalCh)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-29 18:17:30 +02:00
|
|
|
func startGracefulShutdown(ctx context.Context, internalServices *internalServicesContainer) {
|
2023-03-08 15:30:40 +01:00
|
|
|
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
internalServices.pub.Close()
|
|
|
|
|
|
|
|
if err := internalServices.apiService.Shutdown(ctx); err != nil {
|
|
|
|
lo.Fatal("Could not gracefully shutdown api server", "err", err)
|
|
|
|
}
|
|
|
|
}
|