Files
kubescape/main.go
Ian Fox 91ecdaba4e Make a second sigint terminate immediately
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>
2025-06-02 19:12:45 +02:00

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())
}
}