-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When the main process recieves SIGTERM or SIGINT, wait ROUTER_GRACEFUL_SHUTDOWN_DELAY (default: 45) seconds and then signal the reload script with ROUTER_SHUTDOWN=true that a graceful termination is requested. The reload-haproxy script then invokes USR1 on the child processes and waits ROUTER_MAX_SHUTDOWN_TIMEOUT or MAX_RELOAD_WAIT_TIME (default 30) seconds before invoking TERM on the child processes. If TERM is invoked the script exits with 1, indicating that not all processes completed their work. Clients with long running requests should set ROUTER_MAX_SHUTDOWN_TIMEOUT as appropriate to ensure all connections exit cleanly.
- Loading branch information
1 parent
43661b2
commit 7fc4d56
Showing
8 changed files
with
136 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package shutdown | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
) | ||
|
||
var onlyOneSignalHandler = make(chan struct{}) | ||
var shutdownHandler chan os.Signal | ||
|
||
// SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned | ||
// which is closed on one of these signals. If a second signal is caught, the program | ||
// is terminated with exit code 1. | ||
func SetupSignalHandler() <-chan struct{} { | ||
close(onlyOneSignalHandler) // panics when called twice | ||
|
||
shutdownHandler = make(chan os.Signal, 2) | ||
|
||
stop := make(chan struct{}) | ||
signal.Notify(shutdownHandler, shutdownSignals...) | ||
go func() { | ||
<-shutdownHandler | ||
close(stop) | ||
<-shutdownHandler | ||
os.Exit(1) // second signal. Exit directly. | ||
}() | ||
|
||
return stop | ||
} | ||
|
||
// RequestShutdown emulates a received event that is considered as shutdown signal (SIGTERM/SIGINT) | ||
// This returns whether a handler was notified | ||
func RequestShutdown() bool { | ||
if shutdownHandler != nil { | ||
select { | ||
case shutdownHandler <- shutdownSignals[0]: | ||
return true | ||
default: | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// +build !windows | ||
|
||
package shutdown | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package shutdown | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
var shutdownSignals = []os.Signal{os.Interrupt} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters