51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package daemon
|
|
|
|
import (
|
|
"fmt"
|
|
"isle/bootstrap"
|
|
"isle/dnsmasq"
|
|
"path/filepath"
|
|
"sort"
|
|
|
|
"code.betamike.com/micropelago/pmux/pmuxlib"
|
|
)
|
|
|
|
func dnsmasqPmuxProcConfig(
|
|
runtimeDirPath, binDirPath string,
|
|
hostBootstrap bootstrap.Bootstrap,
|
|
daemonConfig Config,
|
|
) (
|
|
pmuxlib.ProcessConfig, error,
|
|
) {
|
|
confPath := filepath.Join(runtimeDirPath, "dnsmasq.conf")
|
|
|
|
hostsSlice := make([]dnsmasq.ConfDataHost, 0, len(hostBootstrap.Hosts))
|
|
for _, host := range hostBootstrap.Hosts {
|
|
hostsSlice = append(hostsSlice, dnsmasq.ConfDataHost{
|
|
Name: string(host.Name),
|
|
IP: host.IP().String(),
|
|
})
|
|
}
|
|
|
|
sort.Slice(hostsSlice, func(i, j int) bool {
|
|
return hostsSlice[i].IP < hostsSlice[j].IP
|
|
})
|
|
|
|
confData := dnsmasq.ConfData{
|
|
Resolvers: daemonConfig.DNS.Resolvers,
|
|
Domain: hostBootstrap.AdminCreationParams.Domain,
|
|
IP: hostBootstrap.ThisHost().IP().String(),
|
|
Hosts: hostsSlice,
|
|
}
|
|
|
|
if err := dnsmasq.WriteConfFile(confPath, confData); err != nil {
|
|
return pmuxlib.ProcessConfig{}, fmt.Errorf("writing dnsmasq.conf to %q: %w", confPath, err)
|
|
}
|
|
|
|
return pmuxlib.ProcessConfig{
|
|
Name: "dnsmasq",
|
|
Cmd: filepath.Join(binDirPath, "dnsmasq"),
|
|
Args: []string{"-d", "-C", confPath},
|
|
}, nil
|
|
}
|