2024-06-24 16:55:36 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-07-06 13:36:48 +00:00
|
|
|
"isle/bootstrap"
|
2024-06-24 16:55:36 +00:00
|
|
|
|
|
|
|
"code.betamike.com/micropelago/pmux/pmuxlib"
|
|
|
|
)
|
|
|
|
|
2024-07-06 13:36:48 +00:00
|
|
|
func (c *Children) newPmuxConfig(
|
2024-07-13 12:34:06 +00:00
|
|
|
ctx context.Context,
|
|
|
|
garageRPCSecret, binDirPath string,
|
|
|
|
daemonConfig Config,
|
2024-07-14 10:19:39 +00:00
|
|
|
garageAdminToken string,
|
2024-07-13 12:34:06 +00:00
|
|
|
hostBootstrap bootstrap.Bootstrap,
|
|
|
|
) (
|
|
|
|
pmuxlib.Config, error,
|
|
|
|
) {
|
2024-06-24 16:55:36 +00:00
|
|
|
nebulaPmuxProcConfig, err := nebulaPmuxProcConfig(
|
2024-07-06 13:36:48 +00:00
|
|
|
c.opts.EnvVars.RuntimeDirPath,
|
|
|
|
binDirPath,
|
|
|
|
daemonConfig,
|
|
|
|
hostBootstrap,
|
2024-06-24 16:55:36 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return pmuxlib.Config{}, fmt.Errorf("generating nebula config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
dnsmasqPmuxProcConfig, err := dnsmasqPmuxProcConfig(
|
2024-07-19 14:50:20 +00:00
|
|
|
c.logger,
|
2024-07-06 13:36:48 +00:00
|
|
|
c.opts.EnvVars.RuntimeDirPath,
|
|
|
|
binDirPath,
|
|
|
|
daemonConfig,
|
2024-07-19 18:49:04 +00:00
|
|
|
hostBootstrap,
|
2024-06-24 16:55:36 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return pmuxlib.Config{}, fmt.Errorf(
|
|
|
|
"generating dnsmasq config: %w", err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
garagePmuxProcConfigs, err := garagePmuxProcConfigs(
|
2024-07-13 12:34:06 +00:00
|
|
|
ctx,
|
2024-07-06 13:36:48 +00:00
|
|
|
c.logger,
|
2024-07-13 12:34:06 +00:00
|
|
|
garageRPCSecret,
|
2024-07-06 13:36:48 +00:00
|
|
|
c.opts.EnvVars.RuntimeDirPath,
|
|
|
|
binDirPath,
|
|
|
|
daemonConfig,
|
2024-07-14 10:19:39 +00:00
|
|
|
garageAdminToken,
|
2024-07-06 13:36:48 +00:00
|
|
|
hostBootstrap,
|
2024-06-24 16:55:36 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return pmuxlib.Config{}, fmt.Errorf(
|
|
|
|
"generating garage children configs: %w", err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-07-19 14:50:20 +00:00
|
|
|
pmuxProcConfigs := garagePmuxProcConfigs
|
|
|
|
pmuxProcConfigs["nebula"] = nebulaPmuxProcConfig
|
|
|
|
pmuxProcConfigs["dnsmasq"] = dnsmasqPmuxProcConfig
|
|
|
|
|
2024-06-24 16:55:36 +00:00
|
|
|
return pmuxlib.Config{
|
2024-07-19 14:50:20 +00:00
|
|
|
Processes: pmuxProcConfigs,
|
2024-06-24 16:55:36 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-07-06 13:36:48 +00:00
|
|
|
func (c *Children) postPmuxInit(
|
|
|
|
ctx context.Context,
|
|
|
|
daemonConfig Config,
|
2024-07-14 10:19:39 +00:00
|
|
|
garageAdminToken string,
|
2024-07-06 13:36:48 +00:00
|
|
|
hostBootstrap bootstrap.Bootstrap,
|
|
|
|
) error {
|
|
|
|
c.logger.Info(ctx, "Waiting for nebula VPN to come online")
|
|
|
|
if err := waitForNebula(ctx, c.logger, hostBootstrap); err != nil {
|
2024-06-24 16:55:36 +00:00
|
|
|
return fmt.Errorf("waiting for nebula to start: %w", err)
|
|
|
|
}
|
|
|
|
|
2024-07-06 13:36:48 +00:00
|
|
|
c.logger.Info(ctx, "Waiting for garage instances to come online")
|
2024-07-14 10:19:39 +00:00
|
|
|
err := waitForGarage(
|
|
|
|
ctx, c.logger, daemonConfig, garageAdminToken, hostBootstrap,
|
|
|
|
)
|
2024-07-06 13:36:48 +00:00
|
|
|
if err != nil {
|
2024-06-24 16:55:36 +00:00
|
|
|
return fmt.Errorf("waiting for garage to start: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|