Adds error exit codes for SIGINT, SIGTERM and SIGKILL (#3662)
This commit is contained in:
@@ -42,6 +42,15 @@ const (
|
||||
|
||||
// Global error exit status.
|
||||
globalErrorExitStatus = 1
|
||||
|
||||
// Global CTRL-C (SIGINT, #2) exit status.
|
||||
globalCancelExitStatus = 130
|
||||
|
||||
// Global SIGKILL (#9) exit status.
|
||||
globalKillExitStatus = 137
|
||||
|
||||
// Global SIGTERM (#15) exit status
|
||||
globalTerminatExitStatus = 143
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
+13
-2
@@ -32,13 +32,24 @@ func trapSignals(sig ...os.Signal) {
|
||||
signal.Notify(sigCh, sig...)
|
||||
|
||||
// Wait for the signal.
|
||||
<-sigCh
|
||||
s := <-sigCh
|
||||
|
||||
// Once signal has been received stop signal Notify handler.
|
||||
|
||||
signal.Stop(sigCh)
|
||||
|
||||
// Cancel the global context
|
||||
globalCancel()
|
||||
|
||||
var exitCode int
|
||||
switch s.String() {
|
||||
case "interrupt":
|
||||
exitCode = globalCancelExitStatus
|
||||
case "killed":
|
||||
exitCode = globalKillExitStatus
|
||||
case "terminated":
|
||||
exitCode = globalTerminatExitStatus
|
||||
default:
|
||||
exitCode = globalErrorExitStatus
|
||||
}
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user