mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 09:59:54 +00:00
Right now, sending a sigint will start a graceful shutdown, which can take quite a while. By calling stop() in the signal handler it unregisters the handler so that a subsequent sigint received during a graceful shutdown will kill the process immediately. Signed-off-by: Ian Fox <code@whatthefox.dev>
32 lines
646 B
Go
32 lines
646 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/kubescape/go-logger"
|
|
"github.com/kubescape/kubescape/v3/cmd"
|
|
)
|
|
|
|
func main() {
|
|
// Capture interrupt signal
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
// Handle interrupt signal
|
|
go func() {
|
|
<-ctx.Done()
|
|
// Perform cleanup or graceful shutdown here
|
|
logger.L().StopError("Received interrupt signal, exiting...")
|
|
// Clear the signal handler so that a second interrupt signal shuts down immediately
|
|
stop()
|
|
}()
|
|
|
|
if err := cmd.Execute(ctx); err != nil {
|
|
stop()
|
|
logger.L().Fatal(err.Error())
|
|
}
|
|
}
|