78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package children
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"isle/bootstrap"
|
|
"isle/daemon/daecommon"
|
|
"isle/dnsmasq"
|
|
"path/filepath"
|
|
|
|
"code.betamike.com/micropelago/pmux/pmuxlib"
|
|
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
|
)
|
|
|
|
func dnsmasqWriteConfig(
|
|
ctx context.Context,
|
|
logger *mlog.Logger,
|
|
runtimeDirPath string,
|
|
networkConfig daecommon.NetworkConfig,
|
|
hostBootstrap bootstrap.Bootstrap,
|
|
) (
|
|
string, bool, error,
|
|
) {
|
|
hosts := make([]dnsmasq.ConfDataHost, 0, len(hostBootstrap.Hosts))
|
|
for _, host := range hostBootstrap.Hosts {
|
|
hosts = append(hosts, dnsmasq.ConfDataHost{
|
|
Name: string(host.Name),
|
|
IP: host.IP().String(),
|
|
})
|
|
}
|
|
|
|
var (
|
|
confPath = filepath.Join(runtimeDirPath, "dnsmasq.conf")
|
|
confData = dnsmasq.ConfData{
|
|
Resolvers: networkConfig.DNS.Resolvers,
|
|
Domain: hostBootstrap.NetworkCreationParams.Domain,
|
|
IP: hostBootstrap.ThisHost().IP().String(),
|
|
Hosts: hosts,
|
|
}
|
|
)
|
|
|
|
changed, err := dnsmasq.WriteConfFile(ctx, logger, confPath, confData)
|
|
if err != nil {
|
|
return "", false, fmt.Errorf(
|
|
"writing dnsmasq.conf to %q: %w", confPath, err,
|
|
)
|
|
}
|
|
|
|
return confPath, changed, nil
|
|
}
|
|
|
|
func dnsmasqPmuxProc(
|
|
ctx context.Context,
|
|
logger *mlog.Logger,
|
|
runtimeDirPath, binDirPath string,
|
|
networkConfig daecommon.NetworkConfig,
|
|
hostBootstrap bootstrap.Bootstrap,
|
|
) (
|
|
*pmuxlib.Process, error,
|
|
) {
|
|
confPath, _, err := dnsmasqWriteConfig(
|
|
ctx, logger, runtimeDirPath, networkConfig, hostBootstrap,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"writing dnsmasq config: %w", err,
|
|
)
|
|
}
|
|
|
|
cfg := pmuxlib.ProcessConfig{
|
|
Cmd: filepath.Join(binDirPath, "dnsmasq"),
|
|
Args: []string{"-d", "-C", confPath},
|
|
}
|
|
cfg = withPmuxLoggers(ctx, logger, "dnsmasq", cfg)
|
|
|
|
return pmuxlib.NewProcess(cfg), nil
|
|
}
|