k8s.io/kubernetes@v1.29.3/test/images/agnhost/pause/pause.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 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 // CmdPause is used by agnhost Cobra. 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 }