Skip to content
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 systemd notify support to Agent. Resolves: #7028 #9802

Merged
merged 5 commits into from Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions command/agent.go
Expand Up @@ -15,6 +15,7 @@ import (
"sync"
"time"

"github.com/hashicorp/consul/agent/systemd"
ncabatoff marked this conversation as resolved.
Show resolved Hide resolved
"github.com/hashicorp/errwrap"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/vault/api"
Expand Down Expand Up @@ -51,6 +52,9 @@ var _ cli.CommandAutocomplete = (*AgentCommand)(nil)
type AgentCommand struct {
*BaseCommand

// NotifierSystemd is called after Vault starts.
NotifierSystemd notifier

ShutdownCh chan struct{}
SighupCh chan struct{}

Expand Down Expand Up @@ -164,6 +168,7 @@ func (c *AgentCommand) AutocompleteFlags() complete.Flags {

func (c *AgentCommand) Run(args []string) int {
f := c.Flags()
c.NotifierSystemd = &systemd.Notifier{}

if err := f.Parse(args); err != nil {
c.UI.Error(err.Error())
Expand Down Expand Up @@ -585,6 +590,10 @@ func (c *AgentCommand) Run(args []string) int {
if err := c.storePidFile(config.PidFile); err != nil {
c.UI.Error(fmt.Sprintf("Error storing PID: %s", err))
return 1
} else {
if notifyErr := c.NotifierSystemd.Notify(systemd.Ready); notifyErr != nil {
c.logger.Debug("server: systemd notify failed", notifyErr)
}
}

defer func() {
Expand Down
13 changes: 13 additions & 0 deletions command/server.go
Expand Up @@ -20,6 +20,7 @@ import (
"sync"
"time"

"github.com/hashicorp/consul/agent/systemd"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/go-hclog"
log "github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -73,9 +74,17 @@ const (
storageTypeConsul = "consul"
)

// notifier is called after a successful Vault start.
type notifier interface {
Notify(string) error
}

type ServerCommand struct {
*BaseCommand

// NotifierSystemd is called after Vault starts.
NotifierSystemd notifier

AuditBackends map[string]audit.Factory
CredentialBackends map[string]logical.Factory
LogicalBackends map[string]logical.Factory
Expand Down Expand Up @@ -799,6 +808,7 @@ func (c *ServerCommand) processLogLevelAndFormat(config *server.Config) (log.Lev

func (c *ServerCommand) Run(args []string) int {
f := c.Flags()
c.NotifierSystemd = &systemd.Notifier{}

if err := f.Parse(args); err != nil {
c.UI.Error(err.Error())
Expand Down Expand Up @@ -1548,6 +1558,9 @@ CLUSTER_SYNTHESIS_COMPLETE:
for {
err := core.UnsealWithStoredKeys(context.Background())
if err == nil {
if notifyErr := c.NotifierSystemd.Notify(systemd.Ready); notifyErr != nil {
c.logger.Debug("server: systemd notify failed", notifyErr)
}
return
}

Expand Down