Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show console dashboard on tty other than tty1 #198

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package/harvester-os/files/etc/tty-dashboard-override.conf
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions package/harvester-os/files/system/oem/91_installer.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
39 changes: 15 additions & 24 deletions package/harvester-os/files/usr/bin/setup-installer.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions package/harvester-os/files/usr/bin/start-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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