server: graceful shutdown for fast failover. Fixes #308

This commit is contained in:
Armon Dadgar
2015-06-17 18:24:56 -07:00
parent c60889572e
commit 70ee1866ca
2 changed files with 31 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ type ServerCommand struct {
CredentialBackends map[string]logical.Factory
LogicalBackends map[string]logical.Factory
ShutdownCh <-chan struct{}
Meta
}
@@ -237,7 +238,14 @@ func (c *ServerCommand) Run(args []string) int {
// Release the log gate.
logGate.Flush()
<-make(chan struct{})
// Wait for shutdown
select {
case <-c.ShutdownCh:
c.Ui.Output("==> Vault shutdown triggered")
if err := core.Shutdown(); err != nil {
c.Ui.Error(fmt.Sprintf("Error with core shutdown: %s", err))
}
}
return 0
}
@@ -407,8 +415,8 @@ General Options:
specified multiple times. If it is a directory, all
files with a ".hcl" or ".json" suffix will be loaded.
-dev Enables Dev mode. In this mode, Vault is completely
in-memory and unsealed. Do not run the Dev server in
-dev Enables Dev mode. In this mode, Vault is completely
in-memory and unsealed. Do not run the Dev server in
production!
-log-level=info Log verbosity. Defaults to "info", will be outputted