Fix dnsmasq crash by creating tftp-root dir and using subnet config
dnsmasq exited with status 3 because the tftp-root directory didn't exist at startup. Also replaced hardcoded 192.168.1.0 in dhcp-range with the configured subnet value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,9 @@ func (s *Supervisor) Start(ctx context.Context, hosts []model.Host) error {
|
|||||||
if err := os.MkdirAll(s.cfg.RuntimeDir, 0o755); err != nil {
|
if err := os.MkdirAll(s.cfg.RuntimeDir, 0o755); err != nil {
|
||||||
return fmt.Errorf("pxe: create runtime dir: %w", err)
|
return fmt.Errorf("pxe: create runtime dir: %w", err)
|
||||||
}
|
}
|
||||||
|
if err := os.MkdirAll(s.cfg.TFTPRoot, 0o755); err != nil {
|
||||||
|
return fmt.Errorf("pxe: create tftp root: %w", err)
|
||||||
|
}
|
||||||
if err := s.writeConfig(hosts); err != nil {
|
if err := s.writeConfig(hosts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -82,8 +85,14 @@ func (s *Supervisor) writeConfig(hosts []model.Host) error {
|
|||||||
return fmt.Errorf("pxe: write dhcp-hostsfile: %w", err)
|
return fmt.Errorf("pxe: write dhcp-hostsfile: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subnet := s.cfg.Subnet
|
||||||
|
if i := strings.Index(subnet, "/"); i != -1 {
|
||||||
|
subnet = subnet[:i]
|
||||||
|
}
|
||||||
|
|
||||||
conf := dnsmasqConf{
|
conf := dnsmasqConf{
|
||||||
Interface: s.cfg.Interface,
|
Interface: s.cfg.Interface,
|
||||||
|
Subnet: subnet,
|
||||||
TFTPRoot: s.cfg.TFTPRoot,
|
TFTPRoot: s.cfg.TFTPRoot,
|
||||||
HostsFile: hostsPath,
|
HostsFile: hostsPath,
|
||||||
PublicURL: s.cfg.PublicURL,
|
PublicURL: s.cfg.PublicURL,
|
||||||
@@ -126,6 +135,7 @@ func (s *Supervisor) startProcess(ctx context.Context) error {
|
|||||||
|
|
||||||
type dnsmasqConf struct {
|
type dnsmasqConf struct {
|
||||||
Interface string
|
Interface string
|
||||||
|
Subnet string
|
||||||
TFTPRoot string
|
TFTPRoot string
|
||||||
HostsFile string
|
HostsFile string
|
||||||
PublicURL string
|
PublicURL string
|
||||||
@@ -137,7 +147,7 @@ port=0
|
|||||||
interface={{.Interface}}
|
interface={{.Interface}}
|
||||||
bind-interfaces
|
bind-interfaces
|
||||||
|
|
||||||
dhcp-range=tag:known,192.168.1.0,proxy
|
dhcp-range=tag:known,{{.Subnet}},proxy
|
||||||
dhcp-hostsfile={{.HostsFile}}
|
dhcp-hostsfile={{.HostsFile}}
|
||||||
dhcp-ignore=tag:!known
|
dhcp-ignore=tag:!known
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user