Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnayak committed Sep 14, 2017
1 parent 5233863 commit 871584e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import (

// ServerCommand is a Command that starts the Vault server.
type ServerCommand struct {
Config *server.Config

AuditBackends map[string]audit.Factory
CredentialBackends map[string]logical.Factory
LogicalBackends map[string]logical.Factory
Expand Down Expand Up @@ -190,9 +188,6 @@ func (c *ServerCommand) Run(args []string) int {
return 1
}

// Store the configuration in the command
c.Config = config

// Ensure that a backend is provided
if config.Storage == nil {
c.Ui.Output("A storage backend must be specified")
Expand Down Expand Up @@ -665,11 +660,17 @@ CLUSTER_SYNTHESIS_COMPLETE:
c.logGate.Flush()

// Write out the PID to the file now that server has successfully started
if err := c.storePid(); err != nil {
if err := c.storePidFile(config.PidFile); err != nil {
c.Ui.Output(fmt.Sprintf("Error storing PID: %v", err))
return 1
}

defer func() {
if err := c.removePidFile(config.PidFile); err != nil {
c.Ui.Output(fmt.Sprintf("Error deleting the PID file: %v", err))
}
}()

// Wait for shutdown
shutdownTriggered := false

Expand Down Expand Up @@ -1236,10 +1237,9 @@ func (c *ServerCommand) AutocompleteFlags() complete.Flags {
}
}

// storePid is used to write out our PID to a file if necessary
func (c *ServerCommand) storePid() error {
// storePidFile is used to write out our PID to a file if necessary
func (c *ServerCommand) storePidFile(pidPath string) error {
// Quit fast if no pidfile
pidPath := c.Config.PidFile
if pidPath == "" {
return nil
}
Expand All @@ -1260,6 +1260,14 @@ func (c *ServerCommand) storePid() error {
return nil
}

// removePidFile is used to cleanup the PID file if necessary
func (c *ServerCommand) removePidFile(pidPath string) error {
if pidPath == "" {
return nil
}
return os.Remove(pidPath)
}

// MakeShutdownCh returns a channel that can be used for shutdown
// notifications for commands. This channel will send a message for every
// SIGINT or SIGTERM received.
Expand Down

0 comments on commit 871584e

Please sign in to comment.