From e42c833553d56c05c48121ad344439392b4c4b03 Mon Sep 17 00:00:00 2001 From: tomalok Date: Mon, 21 Sep 2020 19:43:33 -0700 Subject: [PATCH] eth-eni-setup init script (#87) * eth-eni-setup init script before networking starts up, makes sure eth interfaces match attached ENIs also fixes a permissions problem with eth-eni-hotplug mdev config * fix aarch64 build --- profiles/arch/aarch64-1 | 2 +- profiles/base/1 | 1 + profiles/base/2 | 1 + scripts/setup-ami | 6 +++- .../setup-ami.d/etc/{grub.default => grub} | 0 scripts/setup-ami.d/etc/mdev-ec2.conf | 2 +- scripts/setup-ami.d/eth-eni-setup | 36 +++++++++++++++++++ 7 files changed, 45 insertions(+), 3 deletions(-) rename scripts/setup-ami.d/etc/{grub.default => grub} (100%) create mode 100755 scripts/setup-ami.d/eth-eni-setup diff --git a/profiles/arch/aarch64-1 b/profiles/arch/aarch64-1 index f40af5a..2d1acf7 100644 --- a/profiles/arch/aarch64-1 +++ b/profiles/arch/aarch64-1 @@ -3,7 +3,7 @@ arch = "aarch64" build_arch = "arm64" -build_instance_type = "a1.medium" +build_instance_type = "t4g.nano" apk_tools = "https://github.com/alpinelinux/apk-tools/releases/download/v2.10.3/apk-tools-2.10.3-aarch64-linux.tar.gz" apk_tools_sha256 = "58a07e547c83c3a30eb0a0bd73db57d6bbaf92cc093df7a1d9805631f7d349e3" alpine_keys = "http://dl-cdn.alpinelinux.org/alpine/v3.12/main/aarch64/alpine-keys-2.2-r0.apk" diff --git a/profiles/base/1 b/profiles/base/1 index b219dda..d82270c 100644 --- a/profiles/base/1 +++ b/profiles/base/1 @@ -76,6 +76,7 @@ svcs { } default { chronyd = true + eth-eni-setup = true networking = true sshd = true tiny-ec2-bootstrap = true diff --git a/profiles/base/2 b/profiles/base/2 index 3f1a8b7..3b65243 100644 --- a/profiles/base/2 +++ b/profiles/base/2 @@ -75,6 +75,7 @@ svcs { } default { chronyd = true + eth-eni-setup = true networking = true sshd = true tiny-ec2-bootstrap = true diff --git a/scripts/setup-ami b/scripts/setup-ami index c6aaa50..6084d85 100755 --- a/scripts/setup-ami +++ b/scripts/setup-ami @@ -221,7 +221,7 @@ install_grub_efi() { # install default grub config install -o root -g root -Dm644 -t "$TARGET/etc/default" \ - "$SETUP/etc/grub.default" grub + "$SETUP/etc/grub" # generate/install new config chroot "$TARGET" grub-mkconfig -o /boot/grub/grub.cfg @@ -253,6 +253,10 @@ setup_networking() { ln -sf /usr/share/udhcpc/eth-eni-hook \ "$TARGET/etc/udhcpc/$i" done + + # install ENI interface setup init script + install -o root -g root -Dm755 -t "$TARGET/etc/init.d" \ + "$SETUP/eth-eni-setup" } enable_services() { diff --git a/scripts/setup-ami.d/etc/grub.default b/scripts/setup-ami.d/etc/grub similarity index 100% rename from scripts/setup-ami.d/etc/grub.default rename to scripts/setup-ami.d/etc/grub diff --git a/scripts/setup-ami.d/etc/mdev-ec2.conf b/scripts/setup-ami.d/etc/mdev-ec2.conf index 8cb1c56..860a96e 100644 --- a/scripts/setup-ami.d/etc/mdev-ec2.conf +++ b/scripts/setup-ami.d/etc/mdev-ec2.conf @@ -1,5 +1,5 @@ # additional ENIs -eth[1-9] root:root 0666 */lib/mdev/eth-eni-hotplug +eth[1-9] root:root 0644 */lib/mdev/eth-eni-hotplug # EBS NVMe links nvme[0-9]+n[0-9]+.* root:root 0660 */lib/mdev/nvme-ebs-links diff --git a/scripts/setup-ami.d/eth-eni-setup b/scripts/setup-ami.d/eth-eni-setup new file mode 100755 index 0000000..6216008 --- /dev/null +++ b/scripts/setup-ami.d/eth-eni-setup @@ -0,0 +1,36 @@ +#!/sbin/openrc-run + +description="Sets up interfaces for attached Elastic Network Interfaces" + +IFACE_CFG=/etc/network/interfaces + +depend() { + before net + need sysfs +} + +eni_eths() { + local iface + for iface in /sys/class/net/eth*; do + echo "${iface##*/}" + done +} + +start() { + local iface + + ebegin "Setting up interfaces for attached ENIs" + + cat "$IFACE_CFG.d/lo" > "$IFACE_CFG.new" + + for iface in $(eni_eths); do + [ -f "$IFACE_CFG.d/$iface" ] || + sed -e "s/%%/$iface/g" "$IFACE_CFG.d/DEFAULT" > "$IFACE_CFG.d/$iface" + cat "$IFACE_CFG.d/$iface" >> "$IFACE_CFG.new" + einfo "$iface configured" + done + + mv "$IFACE_CFG.new" "$IFACE_CFG" + + eend "$?" +}