From e87660beeb1d84cfba3ea786ede23dee83a4739b Mon Sep 17 00:00:00 2001 From: "Gerd v. Egidy" Date: Sun, 24 Apr 2022 19:52:04 +0200 Subject: [PATCH] execute sysrescue-configuration.lua only once Before this patch sysrescue-configuration.lua was executed twice each boot: (1) during initramfs stage (2) in the regular system as sysrescue-configuration.service While in theory both runs should create the same output, this isn't guaranteed and differences could appear for example because of network issues. Finding and debugging these is difficult because the output of sysrescue-configuration.lua created during initramfs isn't available anymore when the final system is running. This patch lets sysrescue-configuration.lua just run once during initramfs. The output JSON file is then written to the new tmpfs mounted dir /run/archiso/config/. This dir is also made the new default location for sysrescue-effective-config.json. A symlink from /etc/sysrescue/sysrescue-effective-config.json to the new location is created for compatibility with previous releases. --- .../etc/systemd/scripts/sysrescue-initialize.py | 2 +- .../systemd/system/sysrescue-configuration.service | 13 ------------- airootfs/root/customize_airootfs.sh | 5 ++++- airootfs/usr/bin/sysrescue-configuration.lua | 5 ++--- patches/archiso-v43-07-yaml-config.patch | 7 +++++-- 5 files changed, 12 insertions(+), 20 deletions(-) delete mode 100644 airootfs/etc/systemd/system/sysrescue-configuration.service diff --git a/airootfs/etc/systemd/scripts/sysrescue-initialize.py b/airootfs/etc/systemd/scripts/sysrescue-initialize.py index aa51139..2bf84d6 100755 --- a/airootfs/etc/systemd/scripts/sysrescue-initialize.py +++ b/airootfs/etc/systemd/scripts/sysrescue-initialize.py @@ -19,7 +19,7 @@ errcnt = 0 # Read the effective configuration file # ============================================================================== print(f"====> Read the effective configuration file ...") -effectivecfg = "/etc/sysrescue/sysrescue-effective-config.json" +effectivecfg = "/run/archiso/config/sysrescue-effective-config.json" if os.path.exists(effectivecfg) == False: print (f"Failed to find effective configuration file in {effectivecfg}") sys.exit(1) diff --git a/airootfs/etc/systemd/system/sysrescue-configuration.service b/airootfs/etc/systemd/system/sysrescue-configuration.service deleted file mode 100644 index 9cf8b54..0000000 --- a/airootfs/etc/systemd/system/sysrescue-configuration.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Determine SystemRescue effective configuration -After=network.target network-online.target -Before=sysrescue-initialize.service -Wants=network-online.target - -[Service] -Type=oneshot -ExecStart=/usr/bin/sysrescue-configuration.lua -RemainAfterExit=true - -[Install] -WantedBy=multi-user.target diff --git a/airootfs/root/customize_airootfs.sh b/airootfs/root/customize_airootfs.sh index c32ec1e..0aa203e 100755 --- a/airootfs/root/customize_airootfs.sh +++ b/airootfs/root/customize_airootfs.sh @@ -27,6 +27,10 @@ sed -i 's/#\(HandleLidSwitch=\)suspend/\1ignore/' /etc/systemd/logind.conf # PulseAudio takes care of volume restore ln -sf /dev/null /etc/udev/rules.d/90-alsa-restore.rules +# config symlink +mkdir /etc/sysrescue/ +ln -sf /run/archiso/config/sysrescue-effective-config.json /etc/sysrescue/sysrescue-effective-config.json + # Services systemctl enable NetworkManager.service systemctl enable iptables.service @@ -34,7 +38,6 @@ systemctl enable ip6tables.service systemctl enable pacman-init.service systemctl enable choose-mirror.service systemctl enable sshd.service -systemctl enable sysrescue-configuration.service systemctl enable sysrescue-initialize.service systemctl enable sysrescue-autorun.service systemctl enable qemu-guest-agent.service diff --git a/airootfs/usr/bin/sysrescue-configuration.lua b/airootfs/usr/bin/sysrescue-configuration.lua index 22ae7ad..74fe0c4 100755 --- a/airootfs/usr/bin/sysrescue-configuration.lua +++ b/airootfs/usr/bin/sysrescue-configuration.lua @@ -13,7 +13,7 @@ -- At the end it writes the effective configuration to a JSON file which is meant -- to be ready by any initialisation script which needs to know the configuration. -- Shell scripts can read values from the JSON file using a command such as: --- jq --raw-output '.global.copytoram' /etc/sysrescue/sysrescue-effective-config.json +-- jq --raw-output '.global.copytoram' /run/archiso/config/sysrescue-effective-config.json -- This script requires the following lua packages to run on Arch Linux: -- sudo pacman -Sy lua lua-yaml lua-dkjson lua-http @@ -253,10 +253,9 @@ print (jsoncfgtxt) -- Write the effective configuration to a JSON file -- ============================================================================== print ("====> Writing the effective configuration to a JSON file ...") -output_location = "/etc/sysrescue" +output_location = "/run/archiso/config" output_filename = "sysrescue-effective-config.json" output_fullpath = output_location.."/"..output_filename -lfs.mkdir(output_location) jsoncfgfile = io.open(output_fullpath, "w") if jsoncfgfile == nil then io.stderr:write(string.format("ERROR: Failed to create effective configuration file in %s\n", output_fullpath)) diff --git a/patches/archiso-v43-07-yaml-config.patch b/patches/archiso-v43-07-yaml-config.patch index 5cc953b..ce5b265 100644 --- a/patches/archiso-v43-07-yaml-config.patch +++ b/patches/archiso-v43-07-yaml-config.patch @@ -2,12 +2,15 @@ diff --git a/archiso/initcpio/hooks/archiso b/archiso/initcpio/hooks/archiso index 853652e..53215eb 100644 --- a/archiso/initcpio/hooks/archiso +++ b/archiso/initcpio/hooks/archiso -@@ -197,6 +197,32 @@ archiso_mount_handler() { +@@ -197,6 +197,35 @@ archiso_mount_handler() { fi fi ++ msg ":: Creating config dir ..." ++ mkdir -p /run/archiso/config/ ++ + msg ":: Execute the configuration processing script ..." -+ jsonconfig="/etc/sysrescue/sysrescue-effective-config.json" ++ jsonconfig="/run/archiso/config/sysrescue-effective-config.json" + if ! /usr/bin/sysrescue-configuration.lua > /tmp/sysrescue-configuration.log 2>&1 + then + echo "ERROR: The configuration processing script has failed"