-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'pid_file' config option #3321
Changes from 2 commits
97ed452
5233863
871584e
2d8c07d
4626528
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ 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 | ||
|
@@ -188,6 +190,9 @@ 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") | ||
|
@@ -659,6 +664,12 @@ CLUSTER_SYNTHESIS_COMPLETE: | |
// Release the log gate. | ||
c.logGate.Flush() | ||
|
||
// Write out the PID to the file now that server has successfully started | ||
if err := c.storePid(); err != nil { | ||
c.Ui.Output(fmt.Sprintf("Error storing PID: %v", err)) | ||
return 1 | ||
} | ||
|
||
// Wait for shutdown | ||
shutdownTriggered := false | ||
|
||
|
@@ -1225,6 +1236,30 @@ func (c *ServerCommand) AutocompleteFlags() complete.Flags { | |
} | ||
} | ||
|
||
// storePid is used to write out our PID to a file if necessary | ||
func (c *ServerCommand) storePid() error { | ||
// Quit fast if no pidfile | ||
pidPath := c.Config.PidFile | ||
if pidPath == "" { | ||
return nil | ||
} | ||
|
||
// Open the PID file | ||
pidFile, err := os.OpenFile(pidPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These permissions are too open -- certainly the file should not be world-writable. I suggest 0644. |
||
if err != nil { | ||
return fmt.Errorf("could not open pid file: %v", err) | ||
} | ||
defer pidFile.Close() | ||
|
||
// Write out the PID | ||
pid := os.Getpid() | ||
_, err = pidFile.WriteString(fmt.Sprintf("%d", pid)) | ||
if err != nil { | ||
return fmt.Errorf("could not write to pid file: %v", err) | ||
} | ||
return nil | ||
} | ||
|
||
// 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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ telemetry { | |
max_lease_ttl = "10h" | ||
default_lease_ttl = "10h" | ||
cluster_name = "testcluster" | ||
|
||
pid_file = "./pidfile" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,9 @@ to specify where the configuration is. | |
the standard Vault API address will automatically redirect there. This can also | ||
be provided via the environment variable `VAULT_UI`. | ||
|
||
- `pid_file` `(string: "")` - Path to the file in which Vault server PID should | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say "Path to the file in which the Vault server's Process ID (PID) should be stored." Just in case people think PID is something Vault-y. You never know... |
||
be stored. | ||
|
||
[storage-backend]: /docs/configuration/storage/index.html | ||
[listener]: /docs/configuration/listener/index.html | ||
[telemetry]: /docs/configuration/telemetry.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary, why not just give the path to storePid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. Fixed.