]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(network-manager): run as a service if systemd module is present
authorLukas Nykryn <lnykryn@redhat.com>
Thu, 4 Feb 2021 09:15:45 +0000 (10:15 +0100)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 19 Feb 2021 10:20:59 +0000 (11:20 +0100)
In the current state, services that depend on network need to
use dracut hooks, since nothing with pull in the network
targets into the transaction.

In the future, it would be nice to provide developers on systemd-only
systems the possibility to not use dracut hooks at all, but simply put
normal systemd services into the initrd.

Also, some modules even right now depend on systemd ordering, like
cryptsetup, so let's make sure, that the ordering inside systemd work
properly as well.

modules.d/35network-manager/module-setup.sh
modules.d/35network-manager/nm-run.service [new file with mode: 0644]
modules.d/35network-manager/nm-run.sh
modules.d/40network/netroot.sh

index 92ea7b08f33791b4e764b8469beb04c75e03c6b3..03d9c9b54d1ad16015851e13276e96d5a9edb2fd 100755 (executable)
@@ -34,7 +34,13 @@ install() {
     inst /usr/libexec/nm-initrd-generator
     inst_multiple -o teamd dhclient
     inst_hook cmdline 99 "$moddir/nm-config.sh"
+    if dracut_module_included "systemd"; then
+        inst_simple "${moddir}/nm-run.service" "${systemdsystemunitdir}/nm-run.service"
+        $SYSTEMCTL -q --root "$initdir" enable nm-run.service
+    fi
+
     inst_hook initqueue/settled 99 "$moddir/nm-run.sh"
+
     inst_rules 85-nm-unmanaged.rules
     inst_libdir_file "NetworkManager/$_nm_version/libnm-device-plugin-team.so"
     inst_simple "$moddir/nm-lib.sh" "/lib/nm-lib.sh"
diff --git a/modules.d/35network-manager/nm-run.service b/modules.d/35network-manager/nm-run.service
new file mode 100644 (file)
index 0000000..63fe756
--- /dev/null
@@ -0,0 +1,28 @@
+# This file is part of dracut.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+[Unit]
+#make sure all devices showed up
+Wants=systemd-udev-settle.service
+After=systemd-udev-settle.service
+
+#pull the network targets into transaction
+Wants=network.target network-online.target
+Before=network.target network-online.target
+
+#run before we try to mount anything from the dracut hooks
+Before=dracut-initqueue.service
+
+#do not run, if there is no configuration
+ConditionPathExistsGlob=|/usr/lib/NetworkManager/system-connections/*
+ConditionPathExistsGlob=|/run/NetworkManager/system-connections/*
+ConditionPathExistsGlob=|/etc/NetworkManager/system-connections/*
+ConditionPathExistsGlob=|/etc/sysconfig/network-scripts/ifcfg-*
+
+[Service]
+#run the script and wait before it finishes
+Type=oneshot
+ExecStart=/usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon
+
+[Install]
+WantedBy=initrd.target
index 8b3a06365e4560be36b62e228aee5779b3683838..15d5d16de00559173a5df4e289bebac4eed2d745 100755 (executable)
@@ -1,22 +1,25 @@
 #!/bin/sh
 
+type source_hook >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
 if [ -e /tmp/nm.done ]; then
     return
 fi
 
+[ -z "$DRACUT_SYSTEMD" ] && \
 for i in /usr/lib/NetworkManager/system-connections/* \
          /run/NetworkManager/system-connections/* \
          /etc/NetworkManager/system-connections/* \
          /etc/sysconfig/network-scripts/ifcfg-*; do
   [ -f "$i" ] || continue
   /usr/sbin/NetworkManager --configure-and-quit=initrd --no-daemon
-
-  if [ -s /run/NetworkManager/initrd/hostname ]; then
-      cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname
-  fi
   break
 done
 
+if [ -s /run/NetworkManager/initrd/hostname ]; then
+    cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname
+fi
+
 for _i in /sys/class/net/*
 do
     state=/run/NetworkManager/devices/$(cat $_i/ifindex)
index 207364cdb985dc4f76541a898b34a31abc90173c..6ff1821daf3c2425f31e548a8f97db51b81c070d 100755 (executable)
@@ -65,6 +65,9 @@ if [ -z "$2" ]; then
     fi
 
     # Check: do we really know how to handle (net)root?
+    if [ -z "$root" ]; then
+        root=$(getarg root=)
+    fi
     [ -z "$root" ] && die "No or empty root= argument"
     [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"