blob: fc1fdd016f9830082d42e1b57183ca9cbd5e6de6 [file]
#!/bin/bash
early_id="$(cat /run/machine-id 2>/dev/null)"
current_id="$(cat /etc/machine-id 2>/dev/null)"
if [ -n "$current_id" ] && [ "$early_id" != "$current_id" ]; then
echo "Machine ID changed from $early_id to $current_id. Updating services." >&2
# If we have a journal directory for the old ID, rename it to the new one in /run
if [ -n "$early_id" ] && [ -d "/run/log/journal/$early_id" ]; then
echo "Merging journal from $early_id to $current_id" >&2
# systemd-journald might have both directories if it restarted already.
if [ -d "/run/log/journal/$current_id" ]; then
cp -a "/run/log/journal/$early_id"/* "/run/log/journal/$current_id"/
rm -rf "/run/log/journal/$early_id"
else
mv "/run/log/journal/$early_id" "/run/log/journal/$current_id"
fi
fi
# Restart journald so it picks up the new machine ID and flushes to the correct path
echo "Restarting journald" >&2
systemctl restart systemd-journald
# Re-exec systemd so it also picks up the new machine ID
echo "Re-exec systemd" >&2
systemctl daemon-reexec
else
# Make sure anything in /etc of the rwfs is applied to systemd
echo "Etc overlay applied, reloading systemd" >&2
systemctl daemon-reload
fi
# The hostname isn't set from the static value since it isn't available
# during early boot, read it now that it's available.
if [ -e /etc/hostname ]; then
echo "Re-reading hostname" >&2
hostname -F /etc/hostname
fi