-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (30 loc) · 792 Bytes
/
main.go
File metadata and controls
37 lines (30 loc) · 792 Bytes
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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/grishy/any-sync-bundle/cmd"
)
func main() {
// terminationSignals are signals that cause the program to exit in the supported platforms.
// List from kubectl project.
terminationSignals := []os.Signal{syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT}
ctx, cancel := signal.NotifyContext(context.Background(), terminationSignals...)
defer cancel()
cliRoot := cmd.Root(ctx)
go func() {
<-ctx.Done()
time.Sleep(30 * time.Second)
fmt.Println("\nForced exit by timeout")
os.Exit(1)
}()
if err := cliRoot.Run(os.Args); err != nil {
fmt.Println("\nError:")
fmt.Printf(" > %+v\n", err)
cancel()
os.Exit(1) //nolint:gocritic // need to exit with error code
}
}