Skip to content

Commit

Permalink
overlay: 15fcos: add systemd unit to migrate to systemd-resolved
Browse files Browse the repository at this point in the history
This systemd unit migrates the /etc/resolv.conf file on systems to
point to ../run/systemd/resolve/stub-resolv.conf if users haven't
set up a custom resolv.conf. It will only run on Fedora 33 systems
and will only execute once (a single migration).

Fixes: coreos/fedora-coreos-tracker#646
(cherry picked from commit 56b0ceb)
  • Loading branch information
dustymabe committed Dec 16, 2020
1 parent efb0fbf commit f92809a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions overlay.d/15fcos/usr/lib/systemd/system-preset/45-fcos.preset
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ enable coreos-reset-stub-resolv-selinux-context.path
# Run once on startup to prevent some race conditions with
# NetworkManager and systemd-resolved starting up.
enable coreos-reset-stub-resolv-selinux-context.service
# Enable the migration service to systemd-resolved
enable coreos-migrate-to-systemd-resolved.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This unit is used to migrate existing systems running default
# configurations to systemd-resolved as part of the Fedora 33 change.
# https://fedoraproject.org/wiki/Changes/systemd-resolved
[Unit]
Description=CoreOS Migrate to Systemd Resolved
Documentation=https://github.com/coreos/fedora-coreos-tracker/issues/646
# Run before NetworkManager and systemd-resolved start
Before=NetworkManager.service
Before=systemd-resolved.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/libexec/coreos-migrate-to-systemd-resolved

[Install]
WantedBy=multi-user.target
35 changes: 35 additions & 0 deletions overlay.d/15fcos/usr/libexec/coreos-migrate-to-systemd-resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/bash
set -euo pipefail

# This script will migrate a FCOS system running the default configuration
# to systemd-resolved, which is standard for Fedora 33. For non OSTree Fedora
# systems the RPM post scriptlet takes care of the transition.
# https://fedoraproject.org/wiki/Changes/systemd-resolved
# https://github.com/coreos/fedora-coreos-tracker/issues/646

# If we're not on f33 yet then hard exit.
source /usr/lib/os-release
if [ "$VERSION_ID" == "32" ]; then
echo 'Delaying systemd-resolved migration until Fedora 33'
exit 0
fi

# Here we have a bit of logic:
#
# - Does /etc/resolv.conf exist?
# - It should since tmpfiles will create it otherwise
# - If it doesn't, do nothing.
# - Is /etc/resolv.conf currently being managed by NetworkManager?
# - This is the default configuration in <F33.
# - If yes, then create symlink to stub-resolv.conf
#
if [ -f /etc/resolv.conf ]; then
if [ "$(head -n 1 /etc/resolv.conf)" == '# Generated by NetworkManager' ]; then
echo 'Detected that NetworkManager is managing resolv.conf'
echo 'Migrating to systemd-resolved for Fedora 33 change'
ln -fsv ../run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
fi
fi

# Only run this on Fedora 33 once
systemctl disable coreos-migrate-to-systemd-resolved.service

0 comments on commit f92809a

Please sign in to comment.