Merge pull request #15307 from calavera/stop_signal
Signal to stop a container.
This commit is contained in:
commit
1870f91823
3 changed files with 31 additions and 5 deletions
|
@ -3,8 +3,12 @@
|
||||||
package signal
|
package signal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CatchAll catches all signals and relays them to the specified channel.
|
// CatchAll catches all signals and relays them to the specified channel.
|
||||||
|
@ -21,3 +25,20 @@ func StopCatch(sigc chan os.Signal) {
|
||||||
signal.Stop(sigc)
|
signal.Stop(sigc)
|
||||||
close(sigc)
|
close(sigc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseSignal translates a string to a valid syscall signal.
|
||||||
|
// It returns an error if the signal map doesn't include the given signal.
|
||||||
|
func ParseSignal(rawSignal string) (syscall.Signal, error) {
|
||||||
|
s, err := strconv.Atoi(rawSignal)
|
||||||
|
if err == nil {
|
||||||
|
if s == 0 {
|
||||||
|
return -1, fmt.Errorf("Invalid signal: %s", rawSignal)
|
||||||
|
}
|
||||||
|
return syscall.Signal(s), nil
|
||||||
|
}
|
||||||
|
signal, ok := SignalMap[strings.TrimPrefix(strings.ToUpper(rawSignal), "SIG")]
|
||||||
|
if !ok {
|
||||||
|
return -1, fmt.Errorf("Invalid signal: %s", rawSignal)
|
||||||
|
}
|
||||||
|
return signal, nil
|
||||||
|
}
|
||||||
|
|
|
@ -9,8 +9,11 @@ import (
|
||||||
// Signals used in api/client (no windows equivalent, use
|
// Signals used in api/client (no windows equivalent, use
|
||||||
// invalid signals so they don't get handled)
|
// invalid signals so they don't get handled)
|
||||||
|
|
||||||
|
const (
|
||||||
// SIGCHLD is a signal sent to a process when a child process terminates, is interrupted, or resumes after being interrupted.
|
// SIGCHLD is a signal sent to a process when a child process terminates, is interrupted, or resumes after being interrupted.
|
||||||
const SIGCHLD = syscall.SIGCHLD
|
SIGCHLD = syscall.SIGCHLD
|
||||||
|
|
||||||
// SIGWINCH is a signal sent to a process when its controlling terminal changes its size
|
// SIGWINCH is a signal sent to a process when its controlling terminal changes its size
|
||||||
const SIGWINCH = syscall.SIGWINCH
|
SIGWINCH = syscall.SIGWINCH
|
||||||
|
// DefaultStopSignal is the syscall signal used to stop a container in unix systems.
|
||||||
|
DefaultStopSignal = "SIGTERM"
|
||||||
|
)
|
||||||
|
|
|
@ -11,4 +11,6 @@ import (
|
||||||
const (
|
const (
|
||||||
SIGCHLD = syscall.Signal(0xff)
|
SIGCHLD = syscall.Signal(0xff)
|
||||||
SIGWINCH = syscall.Signal(0xff)
|
SIGWINCH = syscall.Signal(0xff)
|
||||||
|
// DefaultStopSignal is the syscall signal used to stop a container in windows systems.
|
||||||
|
DefaultStopSignal = "15"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue