Skip to content

Commit

Permalink
fix(network-manager): run as a service if systemd module is present
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lnykryn authored and haraldh committed Feb 19, 2021
1 parent 34c73b3 commit c17c5b7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
6 changes: 6 additions & 0 deletions modules.d/35network-manager/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 28 additions & 0 deletions modules.d/35network-manager/nm-run.service
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions modules.d/35network-manager/nm-run.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions modules.d/40network/netroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"

Expand Down

0 comments on commit c17c5b7

Please sign in to comment.