...
1
16
17 package pause
18
19 import (
20 "fmt"
21 "os"
22 "os/signal"
23 "syscall"
24
25 "github.com/spf13/cobra"
26 )
27
28
29 var CmdPause = &cobra.Command{
30 Use: "pause",
31 Short: "Pauses the execution",
32 Long: `Pauses the execution. Useful for keeping the containers running, so other commands can be executed.`,
33 Args: cobra.MaximumNArgs(0),
34 Run: pause,
35 }
36
37 func pause(cmd *cobra.Command, args []string) {
38 fmt.Println("Paused")
39 sigCh := make(chan os.Signal, 1)
40 done := make(chan int, 1)
41 signal.Notify(sigCh, syscall.SIGINT)
42 signal.Notify(sigCh, syscall.SIGTERM)
43 go func() {
44 sig := <-sigCh
45 switch sig {
46 case syscall.SIGINT:
47 done <- 1
48 os.Exit(1)
49 case syscall.SIGTERM:
50 done <- 2
51 os.Exit(2)
52 }
53 }()
54 result := <-done
55 fmt.Printf("exiting %d\n", result)
56 }
57
View as plain text