|
|
|
@ -41,14 +41,14 @@ import ( |
|
|
|
|
// the new bootstrap file is different than the existing one, the existing one
|
|
|
|
|
// is overwritten and true is returned.
|
|
|
|
|
func reloadBootstrap( |
|
|
|
|
env crypticnet.Env, |
|
|
|
|
ctx context.Context, |
|
|
|
|
hostBootstrap bootstrap.Bootstrap, |
|
|
|
|
s3Client garage.S3APIClient, |
|
|
|
|
) ( |
|
|
|
|
bootstrap.Bootstrap, bool, error, |
|
|
|
|
) { |
|
|
|
|
|
|
|
|
|
newHosts, err := bootstrap.GetGarageBootstrapHosts(env.Context, s3Client) |
|
|
|
|
newHosts, err := bootstrap.GetGarageBootstrapHosts(ctx, s3Client) |
|
|
|
|
if err != nil { |
|
|
|
|
return bootstrap.Bootstrap{}, false, fmt.Errorf("getting hosts from garage: %w", err) |
|
|
|
|
} |
|
|
|
@ -69,7 +69,7 @@ func reloadBootstrap( |
|
|
|
|
|
|
|
|
|
newHostBootstrap := hostBootstrap.WithHosts(newHosts) |
|
|
|
|
|
|
|
|
|
if err := writeBootstrapToDataDir(env.DataDirPath, newHostBootstrap); err != nil { |
|
|
|
|
if err := writeBootstrapToDataDir(newHostBootstrap); err != nil { |
|
|
|
|
return bootstrap.Bootstrap{}, false, fmt.Errorf("writing new bootstrap.tgz to data dir: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -81,7 +81,7 @@ func reloadBootstrap( |
|
|
|
|
// until the spawned pmux has returned, and returns a copy of hostBootstrap with
|
|
|
|
|
// updated boostrap info.
|
|
|
|
|
func runDaemonPmuxOnce( |
|
|
|
|
env crypticnet.Env, |
|
|
|
|
ctx context.Context, |
|
|
|
|
hostBootstrap bootstrap.Bootstrap, |
|
|
|
|
daemonConfig daemon.Config, |
|
|
|
|
) ( |
|
|
|
@ -96,17 +96,17 @@ func runDaemonPmuxOnce( |
|
|
|
|
// endpoint.
|
|
|
|
|
s3Client := hostBootstrap.GlobalBucketS3APIClient() |
|
|
|
|
|
|
|
|
|
nebulaPmuxProcConfig, err := nebulaPmuxProcConfig(env, hostBootstrap, daemonConfig) |
|
|
|
|
nebulaPmuxProcConfig, err := nebulaPmuxProcConfig(hostBootstrap, daemonConfig) |
|
|
|
|
if err != nil { |
|
|
|
|
return bootstrap.Bootstrap{}, fmt.Errorf("generating nebula config: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dnsmasqPmuxProcConfig, err := dnsmasqPmuxProcConfig(env, hostBootstrap, daemonConfig) |
|
|
|
|
dnsmasqPmuxProcConfig, err := dnsmasqPmuxProcConfig(hostBootstrap, daemonConfig) |
|
|
|
|
if err != nil { |
|
|
|
|
return bootstrap.Bootstrap{}, fmt.Errorf("generating dnsmasq config: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
garagePmuxProcConfigs, err := garagePmuxProcConfigs(env, hostBootstrap, daemonConfig) |
|
|
|
|
garagePmuxProcConfigs, err := garagePmuxProcConfigs(hostBootstrap, daemonConfig) |
|
|
|
|
if err != nil { |
|
|
|
|
return bootstrap.Bootstrap{}, fmt.Errorf("generating garage children configs: %w", err) |
|
|
|
|
} |
|
|
|
@ -121,12 +121,12 @@ func runDaemonPmuxOnce( |
|
|
|
|
), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
doneCh := env.Context.Done() |
|
|
|
|
doneCh := ctx.Done() |
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup |
|
|
|
|
defer wg.Wait() |
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(env.Context) |
|
|
|
|
ctx, cancel := context.WithCancel(ctx) |
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
wg.Add(1) |
|
|
|
@ -184,7 +184,7 @@ func runDaemonPmuxOnce( |
|
|
|
|
select { |
|
|
|
|
|
|
|
|
|
case <-doneCh: |
|
|
|
|
return bootstrap.Bootstrap{}, env.Context.Err() |
|
|
|
|
return bootstrap.Bootstrap{}, ctx.Err() |
|
|
|
|
|
|
|
|
|
case <-ticker.C: |
|
|
|
|
|
|
|
|
@ -195,7 +195,7 @@ func runDaemonPmuxOnce( |
|
|
|
|
err error |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if hostBootstrap, changed, err = reloadBootstrap(env, hostBootstrap, s3Client); err != nil { |
|
|
|
|
if hostBootstrap, changed, err = reloadBootstrap(ctx, hostBootstrap, s3Client); err != nil { |
|
|
|
|
return bootstrap.Bootstrap{}, fmt.Errorf("reloading bootstrap: %w", err) |
|
|
|
|
|
|
|
|
|
} else if changed { |
|
|
|
@ -232,13 +232,11 @@ var subCmdDaemon = subCmd{ |
|
|
|
|
return fmt.Errorf("parsing flags: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
env := subCmdCtx.env |
|
|
|
|
|
|
|
|
|
if *dumpConfig { |
|
|
|
|
return daemon.CopyDefaultConfig(os.Stdout, env.AppDirPath) |
|
|
|
|
return daemon.CopyDefaultConfig(os.Stdout, envAppDirPath) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
runtimeDirPath := env.RuntimeDirPath |
|
|
|
|
runtimeDirPath := envRuntimeDirPath |
|
|
|
|
|
|
|
|
|
fmt.Fprintf(os.Stderr, "will use runtime directory %q for temporary state\n", runtimeDirPath) |
|
|
|
|
|
|
|
|
@ -260,8 +258,8 @@ var subCmdDaemon = subCmd{ |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
bootstrapDataDirPath = bootstrap.DataDirPath(env.DataDirPath) |
|
|
|
|
bootstrapAppDirPath = bootstrap.AppDirPath(env.AppDirPath) |
|
|
|
|
bootstrapDataDirPath = bootstrap.DataDirPath(envDataDirPath) |
|
|
|
|
bootstrapAppDirPath = bootstrap.AppDirPath(envAppDirPath) |
|
|
|
|
|
|
|
|
|
hostBootstrapPath string |
|
|
|
|
hostBootstrap bootstrap.Bootstrap |
|
|
|
@ -302,12 +300,12 @@ var subCmdDaemon = subCmd{ |
|
|
|
|
|
|
|
|
|
// If the bootstrap file is not being stored in the data dir, copy
|
|
|
|
|
// it there, so it can be loaded from there next time.
|
|
|
|
|
if err := writeBootstrapToDataDir(env.DataDirPath, hostBootstrap); err != nil { |
|
|
|
|
if err := writeBootstrapToDataDir(hostBootstrap); err != nil { |
|
|
|
|
return fmt.Errorf("writing bootstrap.tgz to data dir: %w", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
daemonConfig, err := daemon.LoadConfig(env.AppDirPath, *daemonConfigPath) |
|
|
|
|
daemonConfig, err := daemon.LoadConfig(envAppDirPath, *daemonConfigPath) |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("loading daemon config: %w", err) |
|
|
|
|
} |
|
|
|
@ -317,13 +315,13 @@ var subCmdDaemon = subCmd{ |
|
|
|
|
// up-to-date possible bootstrap. This updated bootstrap will later get
|
|
|
|
|
// updated in garage using bootstrap.PutGarageBoostrapHost, so other
|
|
|
|
|
// hosts will see it as well.
|
|
|
|
|
if hostBootstrap, err = mergeDaemonConfigIntoBootstrap(env, hostBootstrap, daemonConfig); err != nil { |
|
|
|
|
if hostBootstrap, err = mergeDaemonConfigIntoBootstrap(hostBootstrap, daemonConfig); err != nil { |
|
|
|
|
return fmt.Errorf("merging daemon config into bootstrap data: %w", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for { |
|
|
|
|
|
|
|
|
|
hostBootstrap, err = runDaemonPmuxOnce(env, hostBootstrap, daemonConfig) |
|
|
|
|
hostBootstrap, err = runDaemonPmuxOnce(subCmdCtx.ctx, hostBootstrap, daemonConfig) |
|
|
|
|
|
|
|
|
|
if errors.Is(err, context.Canceled) { |
|
|
|
|
return nil |
|
|
|
|