Small changes to how process reloading works
This commit is contained in:
parent
5c41cedea3
commit
88ffa97c0f
@ -48,10 +48,9 @@ func (o *Opts) withDefaults() *Opts {
|
||||
// - dnsmasq
|
||||
// - garage (0 or more, depending on configured storage allocations)
|
||||
type Children struct {
|
||||
logger *mlog.Logger
|
||||
networkConfig daecommon.NetworkConfig
|
||||
runtimeDir toolkit.Dir
|
||||
opts Opts
|
||||
logger *mlog.Logger
|
||||
runtimeDir toolkit.Dir
|
||||
opts Opts
|
||||
|
||||
pmux *pmuxlib.Pmux
|
||||
}
|
||||
@ -80,10 +79,9 @@ func New(
|
||||
}
|
||||
|
||||
c := &Children{
|
||||
logger: logger,
|
||||
networkConfig: networkConfig,
|
||||
runtimeDir: runtimeDir,
|
||||
opts: *opts,
|
||||
logger: logger,
|
||||
runtimeDir: runtimeDir,
|
||||
opts: *opts,
|
||||
}
|
||||
|
||||
pmuxConfig, err := c.newPmuxConfig(
|
||||
@ -112,13 +110,14 @@ func New(
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// RestartDNSMasq rewrites the dnsmasq config and restarts the process.
|
||||
//
|
||||
// TODO block until process has been confirmed to have come back up
|
||||
// successfully.
|
||||
func (c *Children) RestartDNSMasq(hostBootstrap bootstrap.Bootstrap) error {
|
||||
func (c *Children) reloadDNSMasq(
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) error {
|
||||
_, err := dnsmasqWriteConfig(
|
||||
c.runtimeDir.Path, c.networkConfig, hostBootstrap,
|
||||
c.runtimeDir.Path, networkConfig, hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing new dnsmasq config: %w", err)
|
||||
@ -128,40 +127,50 @@ func (c *Children) RestartDNSMasq(hostBootstrap bootstrap.Bootstrap) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestartNebula rewrites the nebula config and restarts the process.
|
||||
//
|
||||
// TODO block until process has been confirmed to have come back up
|
||||
// successfully.
|
||||
func (c *Children) RestartNebula(hostBootstrap bootstrap.Bootstrap) error {
|
||||
func (c *Children) reloadNebula(
|
||||
ctx context.Context,
|
||||
networkConfig daecommon.NetworkConfig,
|
||||
hostBootstrap bootstrap.Bootstrap,
|
||||
) error {
|
||||
_, err := nebulaWriteConfig(
|
||||
c.runtimeDir.Path, c.networkConfig, hostBootstrap,
|
||||
c.runtimeDir.Path, networkConfig, hostBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing a new nebula config: %w", err)
|
||||
}
|
||||
|
||||
c.pmux.Restart("nebula")
|
||||
|
||||
c.logger.Info(ctx, "Waiting for nebula VPN to come online")
|
||||
if err := waitForNebula(ctx, c.logger, hostBootstrap); err != nil {
|
||||
return fmt.Errorf("waiting for nebula to start: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reload applies a ReloadDiff to the Children, using the given bootstrap which
|
||||
// must be the same one which was passed to CalculateReloadDiff.
|
||||
func (c *Children) Reload(
|
||||
ctx context.Context, newBootstrap bootstrap.Bootstrap, diff ReloadDiff,
|
||||
ctx context.Context,
|
||||
newNetworkConfig daecommon.NetworkConfig,
|
||||
newBootstrap bootstrap.Bootstrap,
|
||||
diff ReloadDiff,
|
||||
) error {
|
||||
var errs []error
|
||||
|
||||
if diff.DNSChanged {
|
||||
c.logger.Info(ctx, "Restarting dnsmasq to account for bootstrap changes")
|
||||
if err := c.RestartDNSMasq(newBootstrap); err != nil {
|
||||
errs = append(errs, fmt.Errorf("restarting dnsmasq: %w", err))
|
||||
c.logger.Info(ctx, "Reloading dnsmasq to account for bootstrap changes")
|
||||
if err := c.reloadDNSMasq(newNetworkConfig, newBootstrap); err != nil {
|
||||
errs = append(errs, fmt.Errorf("reloading dnsmasq: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
if diff.NebulaChanged {
|
||||
c.logger.Info(ctx, "Restarting nebula to account for bootstrap changes")
|
||||
if err := c.RestartNebula(newBootstrap); err != nil {
|
||||
errs = append(errs, fmt.Errorf("restarting nebula: %w", err))
|
||||
c.logger.Info(ctx, "Reloading nebula to account for bootstrap changes")
|
||||
err := c.reloadNebula(ctx, newNetworkConfig, newBootstrap)
|
||||
if err != nil {
|
||||
errs = append(errs, fmt.Errorf("reloading nebula: %w", err))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,10 +602,12 @@ func (n *network) reloadWithHosts(
|
||||
|
||||
n.logger.Info(ctx, "Bootstrap has changed, storing new bootstrap")
|
||||
n.l.Lock()
|
||||
networkConfig := n.networkConfig
|
||||
n.currBootstrap = newBootstrap
|
||||
n.l.Unlock()
|
||||
|
||||
if err := n.children.Reload(ctx, newBootstrap, diff); err != nil {
|
||||
err = n.children.Reload(ctx, networkConfig, newBootstrap, diff)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reloading child processes (diff:%+v): %w", diff, err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user