systemd: add initrd-specific services
Decouple from a specific initrd generator (dracut) the systemd services that provide networking in the initrd using NM, thus allowing other systemd-based initrd generators to take advantage of it. These new services are: - `NetworkManager-config-initrd.service`: it starts very early at boot, parses the kernel command line using `nm-initrd-generator` and sets the `/run/NetworkManager/initrd/neednet` flag to activate the other initrd services, and also sets the hostname if needed. - `NetworkManager-initrd.service`: it basically does the same job as the `NetworkManager.service`, but in the initrd. - `NetworkManager-wait-online-initrd.service`: ordered before `network-online.target`, it will allow other services that require networking to delay their start until NM has finished.
This commit is contained in:

committed by
Beniamino Galvani

parent
a90efe91ad
commit
8640ea822f
3
.gitignore
vendored
3
.gitignore
vendored
@@ -84,6 +84,9 @@ test-*.trs
|
||||
/data/org.freedesktop.NetworkManager.policy.in
|
||||
/data/nm-sudo.service
|
||||
/data/nm-priv-helper.service
|
||||
/data/NetworkManager-config-initrd.service
|
||||
/data/NetworkManager-initrd.service
|
||||
/data/NetworkManager-wait-online-initrd.service
|
||||
|
||||
/docs/api/version.xml
|
||||
/docs/api/settings-spec.html
|
||||
|
2
NEWS
2
NEWS
@@ -8,6 +8,8 @@ subject to change and not guaranteed to be compatible with
|
||||
the later release.
|
||||
USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE!
|
||||
|
||||
* Added systemd services to provide networking in the initrd.
|
||||
|
||||
=============================================
|
||||
NetworkManager-1.52
|
||||
Overview of changes since NetworkManager-1.50
|
||||
|
@@ -43,7 +43,7 @@
|
||||
|
||||
%global real_version_major %(printf '%s' '%{real_version}' | sed -n 's/^\\([1-9][0-9]*\\.[0-9][0-9]*\\)\\.[0-9][0-9]*$/\\1/p')
|
||||
|
||||
%global systemd_units NetworkManager.service NetworkManager-wait-online.service NetworkManager-dispatcher.service nm-priv-helper.service
|
||||
%global systemd_units NetworkManager.service NetworkManager-wait-online.service NetworkManager-dispatcher.service nm-priv-helper.service NetworkManager-config-initrd.service NetworkManager-initrd.service NetworkManager-wait-online-initrd.service
|
||||
|
||||
%global systemd_units_cloud_setup nm-cloud-setup.service nm-cloud-setup.timer
|
||||
|
||||
@@ -829,7 +829,7 @@ if [ $1 -eq 0 ]; then
|
||||
# Don't kill networking entirely just on package remove
|
||||
#/bin/systemctl stop NetworkManager.service >/dev/null 2>&1 || :
|
||||
fi
|
||||
%systemd_preun NetworkManager-wait-online.service NetworkManager-dispatcher.service nm-priv-helper.service
|
||||
%systemd_preun NetworkManager-wait-online.service NetworkManager-dispatcher.service nm-priv-helper.service NetworkManager-config-initrd.service NetworkManager-initrd.service NetworkManager-wait-online-initrd.service
|
||||
|
||||
|
||||
%if %{with ifcfg_rh}
|
||||
@@ -927,6 +927,9 @@ fi
|
||||
%{_unitdir}/NetworkManager-wait-online.service
|
||||
%{_unitdir}/NetworkManager-dispatcher.service
|
||||
%{_unitdir}/nm-priv-helper.service
|
||||
%{_unitdir}/NetworkManager-config-initrd.service
|
||||
%{_unitdir}/NetworkManager-initrd.service
|
||||
%{_unitdir}/NetworkManager-wait-online-initrd.service
|
||||
%dir %{_datadir}/doc/NetworkManager/examples
|
||||
%{_datadir}/doc/NetworkManager/examples/server.conf
|
||||
%if %{with ifcfg_warning} || %{with ifcfg_migrate}
|
||||
|
27
data/NetworkManager-config-initrd.service.in
Normal file
27
data/NetworkManager-config-initrd.service.in
Normal file
@@ -0,0 +1,27 @@
|
||||
[Unit]
|
||||
Description=NetworkManager Configuration (initrd)
|
||||
DefaultDependencies=no
|
||||
Wants=systemd-journald.socket
|
||||
After=systemd-journald.socket
|
||||
Before=systemd-udevd.service systemd-udev-trigger.service
|
||||
ConditionPathExists=/etc/initrd-release
|
||||
|
||||
[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
|
||||
|
||||
[Install]
|
||||
WantedBy=initrd.target
|
32
data/NetworkManager-initrd.service.in
Normal file
32
data/NetworkManager-initrd.service.in
Normal file
@@ -0,0 +1,32 @@
|
||||
[Unit]
|
||||
Description=NetworkManager (initrd)
|
||||
DefaultDependencies=no
|
||||
Wants=systemd-udev-trigger.service network.target
|
||||
After=systemd-udev-trigger.service network-pre.target dbus.service NetworkManager-config-initrd.service
|
||||
Before=network.target
|
||||
BindsTo=dbus.service
|
||||
ConditionPathExists=/etc/initrd-release
|
||||
ConditionPathExists=/run/NetworkManager/initrd/neednet
|
||||
ConditionPathExistsGlob=|/usr/lib/NetworkManager/system-connections/*
|
||||
ConditionPathExistsGlob=|/run/NetworkManager/system-connections/*
|
||||
ConditionPathExistsGlob=|/etc/NetworkManager/system-connections/*
|
||||
|
||||
[Service]
|
||||
Type=dbus
|
||||
BusName=org.freedesktop.NetworkManager
|
||||
ExecReload=/usr/bin/busctl call org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager Reload u 0
|
||||
ExecStart=@sbindir@/NetworkManager
|
||||
# NM doesn't want systemd to kill its children for it
|
||||
KillMode=process
|
||||
Environment=NM_CONFIG_ENABLE_TAG=initrd
|
||||
Restart=on-failure
|
||||
ProtectSystem=true
|
||||
ProtectHome=read-only
|
||||
|
||||
[Install]
|
||||
WantedBy=initrd.target
|
||||
# We want to enable NetworkManager-wait-online-initrd.service whenever this
|
||||
# service is enabled. NetworkManager-wait-online-initrd.service has
|
||||
# WantedBy=network-online.target, so enabling it only has an effect if
|
||||
# network-online.target itself is enabled or pulled in by some other unit.
|
||||
Also=NetworkManager-config-initrd.service NetworkManager-wait-online-initrd.service
|
26
data/NetworkManager-wait-online-initrd.service.in
Normal file
26
data/NetworkManager-wait-online-initrd.service.in
Normal file
@@ -0,0 +1,26 @@
|
||||
[Unit]
|
||||
Description=NetworkManager Wait Online (initrd)
|
||||
DefaultDependencies=no
|
||||
Requires=NetworkManager-initrd.service
|
||||
After=NetworkManager-initrd.service
|
||||
Before=network-online.target
|
||||
ConditionPathExists=/etc/initrd-release
|
||||
ConditionPathExists=/run/NetworkManager/initrd/neednet
|
||||
|
||||
[Service]
|
||||
# `nm-online -s` waits until the point when NetworkManager logs
|
||||
# "startup complete". That is when startup actions are settled and
|
||||
# devices and profiles reached a conclusive activated or deactivated
|
||||
# state. It depends on which profiles are configured to autoconnect and
|
||||
# also depends on profile settings like ipv4.may-fail/ipv6.may-fail,
|
||||
# which affect when a profile is considered fully activated.
|
||||
# Check NetworkManager logs to find out why wait-online takes a certain
|
||||
# time.
|
||||
|
||||
Type=oneshot
|
||||
ExecStart=@bindir@/nm-online -s -q
|
||||
RemainAfterExit=yes
|
||||
Environment=NM_ONLINE_TIMEOUT=3600
|
||||
|
||||
[Install]
|
||||
WantedBy=initrd.target network-online.target
|
@@ -13,6 +13,9 @@ if install_systemdunitdir
|
||||
'NetworkManager.service',
|
||||
'nm-priv-helper.service',
|
||||
'NetworkManager-wait-online.service',
|
||||
'NetworkManager-config-initrd.service',
|
||||
'NetworkManager-initrd.service',
|
||||
'NetworkManager-wait-online-initrd.service',
|
||||
]
|
||||
|
||||
foreach service: services
|
||||
|
Reference in New Issue
Block a user