Add a generic registerShutdown function for graceful exit (#2344)

* Add a generic registerShutdown function for graceful exit
* Add shutdown callback test case
This commit is contained in:
Anis Elleuch
2016-08-05 22:48:31 +02:00
committed by Harshavardhana
parent 62c0612eac
commit d28fb5fe23
7 changed files with 127 additions and 21 deletions
-13
View File
@@ -17,11 +17,9 @@
package main
import (
"os"
"path/filepath"
"strings"
"sync"
"syscall"
)
const (
@@ -35,17 +33,6 @@ const (
bucketMetaPrefix = "buckets"
)
// Register callback functions that needs to be called when process shutsdown.
// For now, SIGINT triggers the callbacks, in future controller can trigger
// shutdown callbacks.
func registerShutdown(callback func()) {
go func() {
trapCh := signalTrap(os.Interrupt, syscall.SIGTERM)
<-trapCh
callback()
}()
}
// isErrIgnored should we ignore this error?, takes a list of errors which can be ignored.
func isErrIgnored(err error, ignoredErrs []error) bool {
for _, ignoredErr := range ignoredErrs {