shutdown gracefully on SIGINT/SIGTERM

Signed-off-by: Steve Kriss <steve@heptio.com>
This commit is contained in:
Steve Kriss
2018-05-10 16:20:51 -07:00
parent 9fc1711d45
commit 09c20b51e6

View File

@@ -21,10 +21,13 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/signal"
"reflect"
"sort"
"strings"
"sync"
"syscall"
"time"
"github.com/heptio/ark/pkg/buildinfo"
@@ -237,6 +240,8 @@ func (s *server) run() error {
s.watchConfig(originalConfig)
s.handleShutdownSignals()
if err := s.initBackupService(config); err != nil {
return err
}
@@ -364,6 +369,17 @@ func (s *server) watchConfig(config *api.Config) {
})
}
func (s *server) handleShutdownSignals() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
s.logger.Infof("Received signal %s, gracefully shutting down", sig)
s.cancelFunc()
}()
}
func (s *server) initBackupService(config *api.Config) error {
s.logger.Info("Configuring cloud provider for backup service")
objectStore, err := getObjectStore(config.BackupStorageProvider.CloudProviderConfig, s.pluginManager)