Send systemd notifications for both server and agent (#3430)

* update agent to sent systemd notify after everything starts
This commit is contained in:
Brian Downs 2021-06-15 07:20:26 -04:00 committed by GitHub
parent a7d1159ba6
commit 88f95ec409
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -114,6 +114,10 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
return err return err
} }
} }
notifySocket := os.Getenv("NOTIFY_SOCKET")
os.Unsetenv("NOTIFY_SOCKET")
if err := setupTunnelAndRunAgent(ctx, nodeConfig, cfg, proxy); err != nil { if err := setupTunnelAndRunAgent(ctx, nodeConfig, cfg, proxy); err != nil {
return err return err
} }
@ -141,6 +145,9 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
} }
} }
os.Setenv("NOTIFY_SOCKET", notifySocket)
systemd.SdNotify(true, "READY=1\n")
<-ctx.Done() <-ctx.Done()
return ctx.Err() return ctx.Err()
} }
@ -232,7 +239,7 @@ func Run(ctx context.Context, cfg cmds.Agent) error {
cfg.Token = newToken.String() cfg.Token = newToken.String()
break break
} }
systemd.SdNotify(true, "READY=1\n")
return run(ctx, cfg, proxy) return run(ctx, cfg, proxy)
} }

View File

@ -362,8 +362,6 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
} }
logrus.Info("Starting " + version.Program + " " + app.App.Version) logrus.Info("Starting " + version.Program + " " + app.App.Version)
notifySocket := os.Getenv("NOTIFY_SOCKET")
os.Unsetenv("NOTIFY_SOCKET")
ctx := signals.SetupSignalHandler(context.Background()) ctx := signals.SetupSignalHandler(context.Background())
@ -379,9 +377,9 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
<-serverConfig.ControlConfig.Runtime.ETCDReady <-serverConfig.ControlConfig.Runtime.ETCDReady
logrus.Info("ETCD server is now running") logrus.Info("ETCD server is now running")
} }
logrus.Info(version.Program + " is up and running") logrus.Info(version.Program + " is up and running")
if notifySocket != "" { if cfg.DisableAgent && os.Getenv("NOTIFY_SOCKET") != "" {
os.Setenv("NOTIFY_SOCKET", notifySocket)
systemd.SdNotify(true, "READY=1\n") systemd.SdNotify(true, "READY=1\n")
} }
}() }()