Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix systemd-networkd-wait-online race #181

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ type backend interface {
// A list of udev rules
UdevRules() []string

// The match expression used for the networkd configuration
NetworkdMatch() string

// The tty used for the job output
JobOutputTTY() string

Expand Down
4 changes: 0 additions & 4 deletions backend_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ func (b qemuBackend) UdevRules() []string {
return udevRules
}

func (b qemuBackend) NetworkdMatch() string {
return "e*"
}

func (b qemuBackend) JobOutputTTY() string {
// By default we send job output to the second virtio console,
// reserving /dev/ttyS0 for boot messages (which we ignore)
Expand Down
4 changes: 0 additions & 4 deletions backend_uml.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ func (b umlBackend) UdevRules() []string {
return udevRules
}

func (b umlBackend) NetworkdMatch() string {
return "vec*"
}

func (b umlBackend) JobOutputTTY() string {
// Send the fakemachine job output to the right console
if b.machine.showBoot {
Expand Down
22 changes: 19 additions & 3 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,26 @@ exec /lib/systemd/systemd
`
const networkdTemplate = `
[Match]
Name=%[1]s
Type=ether

[Network]
DHCP=ipv4
# Disable link-local address to speedup boot
LinkLocalAddressing=no
IPv6AcceptRA=no
`

const networkdLinkTemplate = `
[Match]
Type=ether

[Link]
# Give the interface a static name
Name=ethernet0
`

const commandWrapper = `#!/bin/sh
/lib/systemd/systemd-networkd-wait-online -q
/lib/systemd/systemd-networkd-wait-online -q --interface=ethernet0
if [ $? != 0 ]; then
echo "WARNING: Network setup failed"
echo "== Journal =="
Expand Down Expand Up @@ -798,7 +808,13 @@ func (m *Machine) startup(command string, extracontent [][2]string) (int, error)
}

err = w.WriteFile("/etc/systemd/network/ethernet.network",
fmt.Sprintf(networkdTemplate, backend.NetworkdMatch()), 0444)
networkdTemplate, 0444)
if err != nil {
return -1, err
}

err = w.WriteFile("/etc/systemd/network/10-ethernet.link",
networkdLinkTemplate, 0444)
if err != nil {
return -1, err
}
Expand Down
Loading