forked from kubescape/kubescape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (42 loc) · 1.08 KB
/
Copy pathmain.go
File metadata and controls
49 lines (42 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/kubescape/backend/pkg/versioncheck"
"github.com/kubescape/go-logger"
"github.com/kubescape/kubescape/v3/cmd"
)
// GoReleaser will fill these at build time
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
// Set the global build number for version checking
versioncheck.BuildNumber = version
// Capture interrupt signal on a dedicated channel so the watcher can
// distinguish a real signal from a normal cancel() on graceful exit.
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigCh)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
select {
case <-sigCh:
logger.L().StopError("Received interrupt signal, exiting...")
// Clear the signal handler so a second signal terminates immediately.
signal.Stop(sigCh)
cancel()
case <-ctx.Done():
// Normal shutdown — no log line.
}
}()
if err := cmd.Execute(ctx, version, commit, date); err != nil {
cancel()
os.Exit(1)
}
}