mirror of
https://github.com/pgsty/minio.git
synced 2026-07-19 04:00:25 +03:00
utils: Take monitorShutdownSignal to take an exitFunc which would executed upon error. (#2378)
This hook approach allows program to keep running but being able to handle exiting of the program in the dynamic way. Fixes #2377
This commit is contained in:
@@ -100,10 +100,13 @@ func registerObjectStorageShutdown(callback func() errCode) {
|
||||
shutdownObjectStorageCallbacks = append(shutdownObjectStorageCallbacks, callback)
|
||||
}
|
||||
|
||||
// Represents a type of an exit func which will be invoked during shutdown signal.
|
||||
type onExitFunc func(code int)
|
||||
|
||||
// Start to monitor shutdownSignal to execute shutdown callbacks
|
||||
func monitorShutdownSignal() {
|
||||
func monitorShutdownSignal(onExitFn onExitFunc) {
|
||||
go func() {
|
||||
// Monitor processus signal
|
||||
// Monitor signals.
|
||||
trapCh := signalTrap(os.Interrupt, syscall.SIGTERM)
|
||||
for {
|
||||
select {
|
||||
@@ -115,7 +118,7 @@ func monitorShutdownSignal() {
|
||||
for _, callback := range shutdownCallbacks {
|
||||
exitCode := callback()
|
||||
if exitCode != exitSuccess {
|
||||
os.Exit(int(exitCode))
|
||||
onExitFn(int(exitCode))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -123,11 +126,11 @@ func monitorShutdownSignal() {
|
||||
for _, callback := range shutdownObjectStorageCallbacks {
|
||||
exitCode := callback()
|
||||
if exitCode != exitSuccess {
|
||||
os.Exit(int(exitCode))
|
||||
onExitFn(int(exitCode))
|
||||
}
|
||||
|
||||
}
|
||||
os.Exit(int(exitSuccess))
|
||||
onExitFn(int(exitSuccess))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user