From 403dbbd6e2b4138666f6ccc9e369684cf5228d46 Mon Sep 17 00:00:00 2001 From: John Liu Date: Sun, 19 Dec 2021 23:14:45 +0800 Subject: [PATCH] Show console dashboard on tty other than tty1 - Need to move "setup-installer.sh" to initramfs stage for enabling/disabling getty services - Because cOS' initramfs stage runs in chroot env and /tmp is not in BindPaths, here-document can't be used. Thus we need to store that override.conf as "/etc/tty-dashboard-override.conf", then copy this file to the correct service.d directory as drop-ins. - For testing purpose, the console dashboard will always show on tty6. TODOs: - How to determine which tty to show console dashboard? - Provide a Harvester config such as `console_tty` for users to choose which tty to show the dashboard --- .../files/etc/tty-dashboard-override.conf | 13 +++++++ .../files/system/oem/91_installer.yaml | 9 +++-- .../files/usr/bin/setup-installer.sh | 39 +++++++------------ .../files/usr/bin/start-installer.sh | 6 +++ 4 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 package/harvester-os/files/etc/tty-dashboard-override.conf diff --git a/package/harvester-os/files/etc/tty-dashboard-override.conf b/package/harvester-os/files/etc/tty-dashboard-override.conf new file mode 100644 index 000000000..7672b4357 --- /dev/null +++ b/package/harvester-os/files/etc/tty-dashboard-override.conf @@ -0,0 +1,13 @@ +# The folder will be renamed to the getty service that needs to start TTY Dashboard +[Service] +EnvironmentFile=-/etc/rancher/installer/env + +# Do not show kernel messages on this TTY, it messes up the installer UI +# NOTE: it doesn't work for serial console +ExecStartPre=/usr/bin/setterm --msg off + +# clear the original command in getty@.service +ExecStart= + +# override with the new command +ExecStart=-/sbin/agetty -n -l /usr/bin/start-installer.sh %I $TERM diff --git a/package/harvester-os/files/system/oem/91_installer.yaml b/package/harvester-os/files/system/oem/91_installer.yaml index f93213a1d..b2ffc2eb7 100644 --- a/package/harvester-os/files/system/oem/91_installer.yaml +++ b/package/harvester-os/files/system/oem/91_installer.yaml @@ -1,10 +1,11 @@ name: "Setup installer" stages: - boot: - - commands: - - setup-installer.sh initramfs: - - environment_file: "/etc/rancher/installer/env" + - name: "Set up installer" + commands: + - setup-installer.sh + - name: "Set up installer environment if installed finished" + environment_file: "/etc/rancher/installer/env" environment: HARVESTER_DASHBOARD: "true" KUBECONFIG: /etc/rancher/rke2/rke2.yaml diff --git a/package/harvester-os/files/usr/bin/setup-installer.sh b/package/harvester-os/files/usr/bin/setup-installer.sh index 0c62cefb1..ec0e3af19 100755 --- a/package/harvester-os/files/usr/bin/setup-installer.sh +++ b/package/harvester-os/files/usr/bin/setup-installer.sh @@ -1,40 +1,31 @@ #!/bin/bash -# Create a systemd drop-in unit to run installer on the first console tty. e.g., -# if a system is booted with `console=tty1 console=ttyS0` parameters, the -# script replaces the default login prompt on tty1 wth the installer. - +# Create a systemd drop-in unit to run installer as TTY Dashboard on a +# "non-system-console" virtual console or user specified serial console. create_drop_in() { DROP_IN_DIRECTORY=$1 echo "Create installer drop-in in ${DROP_IN_DIRECTORY}..." - mkdir -p ${DROP_IN_DIRECTORY} - cat > "${DROP_IN_DIRECTORY}/override.conf" <<"EOF" -[Service] -EnvironmentFile=-/etc/rancher/installer/env - -# Do not show kernel messages on this TTY, it messes up the installer UI -# NOTE: it doesn't work for serial console -ExecStartPre=/usr/bin/setterm --msg off - -# clear the original command in getty@.service -ExecStart= - -# override with the new command -ExecStart=-/sbin/agetty -n -l /usr/bin/start-installer.sh %I $TERM -EOF - + mkdir -p ${DROP_IN_DIRECTORY} + cp /etc/tty-dashboard-override.conf "${DROP_IN_DIRECTORY}/override.conf" } - # reverse the ttys to start from the last one for TTY in $(cat /sys/class/tty/console/active); do tty_num=${TTY#tty} - # tty1 ~ tty64 + # If console is on tty1 ~ tty64, we will show Harvester TTY Dashboard on other virtual terminal if [[ $tty_num =~ ^[0-9]+$ ]]; then - create_drop_in "/run/systemd/system/getty@${TTY}.service.d" + unset dashboard_tty + if [[ $tty_num -ge 6 ]]; then + dashboard_tty="tty2" + else + dashboard_tty="tty$((tty_num+1))" + fi + create_drop_in "/run/systemd/system/getty@${dashboard_tty}.service.d" + systemctl enable "getty@${dashboard_tty}.service" + systemctl disable getty@tty1.service break fi @@ -45,7 +36,7 @@ for TTY in $(cat /sys/class/tty/console/active); do if [ "x${tty_type}" = "x0" ]; then continue fi - + create_drop_in "/run/systemd/system/serial-getty@${TTY}.service.d" break done diff --git a/package/harvester-os/files/usr/bin/start-installer.sh b/package/harvester-os/files/usr/bin/start-installer.sh index 05605734e..d857837b3 100755 --- a/package/harvester-os/files/usr/bin/start-installer.sh +++ b/package/harvester-os/files/usr/bin/start-installer.sh @@ -6,6 +6,12 @@ fi export TERM=linux +tty_num=${TTY#/dev/tty} +if [[ ${tty_num} =~ ^[0-9]+$ ]]; then + # Switch virtual terminal + chvt ${tty_num} +fi + harvester-installer # Do not allow bash prompt if the installer doesn't exit with status 0 bash -l