NetworkManager/data/NetworkManager-config-initrd.service.in
Antonio Alvarez Feijoo 636fb5ef24 systemd: install initrd services using a generator
Since both `NetworkManager.service` and `NetworkManager-initrd.service` are
allocated for the same bus name (`org.freedesktop.NetworkManager`) and this is
not allowed, the best option is to use a systemd generator to install them only
in the initrd, instead of setting fixed Install sections.

Fixes #1814
2025-11-20 13:26:15 +00:00

24 lines
844 B
SYSTEMD

[Unit]
Description=NetworkManager Configuration (initrd)
AssertPathExists=/etc/initrd-release
DefaultDependencies=no
Wants=systemd-journald.socket
After=systemd-journald.socket
Before=systemd-udevd.service systemd-udev-trigger.service
[Service]
Type=oneshot
ExecStartPre=/bin/sh -c "rm -f /run/NetworkManager/system-connections/*"
ExecStart=/bin/sh -c "@libexecdir@/nm-initrd-generator -- $(cat /proc/cmdline)"
ExecStartPost=/bin/sh -c ' \
for i in /{usr/lib,run,etc}/NetworkManager/system-connections/*; do \
[ -f "$i" ] || continue; \
mkdir -p /run/NetworkManager/initrd; \
: > /run/NetworkManager/initrd/neednet; \
break; \
done; \
if [ -s /run/NetworkManager/initrd/hostname ]; then \
cat /run/NetworkManager/initrd/hostname > /proc/sys/kernel/hostname; \
fi \
'
RemainAfterExit=yes