Skip to content

Commit

Permalink
Merge pull request #485 from KKoukiou/workaround-firefox-crash-boot-iso
Browse files Browse the repository at this point in the history
Fix bridge crashing installation on boot.iso
  • Loading branch information
KKoukiou authored Oct 25, 2024
2 parents ea33afd + 1f66fa2 commit 913cf8c
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 56 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ install: $(DIST_TEST) po/LINGUAS
mkdir -p $(DESTDIR)/usr/libexec/anaconda
cp webui-desktop $(DESTDIR)/usr/libexec/anaconda
ln -sTfr $(DESTDIR)/usr/share/pixmaps/fedora-logo-sprite.svg $(DESTDIR)/usr/share/cockpit/$(PACKAGE_NAME)/logo.svg
mkdir -p $(DESTDIR)/usr/lib/systemd/system/
cp src/systemd/webui-cockpit-ws.service $(DESTDIR)/usr/lib/systemd/system/

# required for running integration tests;
TEST_NPMS = \
Expand Down
5 changes: 5 additions & 0 deletions packaging/anaconda-webui.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ BuildArch: noarch
BuildRequires: libappstream-glib
BuildRequires: make
BuildRequires: gettext
# Needed for the unitdir macro
BuildRequires: systemd-rpm-macros

%global anacondacorever 0

Expand All @@ -20,6 +22,8 @@ BuildRequires: gettext
%global cockpitver 275
%global cockpitstorver 311

%define _unitdir /usr/lib/systemd/system

Requires: cockpit-storaged >= %{cockpitstorver}
Requires: cockpit-bridge >= %{cockpitver}
Requires: cockpit-ws >= %{cockpitver}
Expand Down Expand Up @@ -79,6 +83,7 @@ exit 0
%{_datadir}/anaconda/firefox-theme/live/user.js
%{_datadir}/anaconda/firefox-theme/live/chrome/userChrome.css
%{_libexecdir}/anaconda/webui-desktop
%{_unitdir}/webui-cockpit-ws.service


# The changelog is automatically generated and merged
Expand Down
14 changes: 14 additions & 0 deletions src/systemd/webui-cockpit-ws.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Cockpit Web Service for Anaconda Installer
After=network.target

[Service]
Type=simple
EnvironmentFile=/tmp/webui-cockpit-ws.env
Environment="COCKPIT_SUPERUSER=pkexec"
ExecStart=/usr/libexec/cockpit-ws -p 80 -a "$WEBUI_ADDRESS" --no-tls --local-session=cockpit-bridge
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
7 changes: 7 additions & 0 deletions test/anacondalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def setUp(self):
self.addCleanup(self.resetUsers)
self.addCleanup(self.resetStorage)
self.addCleanup(self.resetLanguage)
self.addCleanup(self.resetMisc)

super().setUp()

Expand Down Expand Up @@ -150,6 +151,12 @@ def resetStorage(self):
s.dbus_set_initialization_mode(-1)
s.dbus_scan_devices()

def resetMisc(self):
# Restart cockpit-ws/cockpit-bridge to avoid crashes in the next test
m = self.machine

m.execute("systemctl restart webui-cockpit-ws.service")

def downloadLogs(self):
if not self.ext_logging:
return
Expand Down
2 changes: 1 addition & 1 deletion test/machine_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def start(self):
"--noautoconsole "
f"--graphics vnc,listen={self.ssh_address} "
"--extra-args "
f"'inst.sshd inst.webui.remote inst.webui inst.updates=http://10.0.2.2:{self.http_updates_img_port}/{self.label}-updates.img' "
f"'inst.sshd inst.webui.remote inst.updates=http://10.0.2.2:{self.http_updates_img_port}/{self.label}-updates.img' "
"--network none "
f"--qemu-commandline="
"'-netdev user,id=hostnet0,"
Expand Down
7 changes: 0 additions & 7 deletions test/vm.install
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ BOTS_DIR = os.path.realpath(f'{__file__}/../../bots')
sys.path.append(BOTS_DIR)

missing_packages = "cockpit-ws cockpit-bridge fedora-logos udisks2 libudisks2 udisks2-lvm2 udisks2-btrfs udisks2-iscsi"
# Install missing firefox dependencies.
# Resolving all dependencies with dnf download is possible,
# but it packs to many packages to updates.img
missing_packages_incl_deps = "firefox"

from machine.machine_core import machine_virtual

Expand Down Expand Up @@ -89,9 +85,6 @@ def vm_install(image, verbose, quick):
# Then we can enable this only for the various scenarios above
if packages_to_download is not None:
machine.execute(f"dnf download --destdir /var/tmp/build/ {packages_to_download}", stdout=sys.stdout, timeout=300)
machine.execute(
f"dnf download --resolve --setopt=install_weak_deps=False --destdir /var/tmp/build/ {missing_packages_incl_deps}",
stdout=sys.stdout, timeout=300)

# download rpms
vm_rpms = machine.execute("find /var/tmp/build -name '*.rpm' -not -name '*.src.rpm'").strip().split()
Expand Down
96 changes: 48 additions & 48 deletions webui-desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,65 +64,65 @@ case "$1" in
;;
esac

# prepare empty firefox profile dir with theme based on the passed profile id
FIREFOX_THEME_DIR="/usr/share/anaconda/firefox-theme"
FIREFOX_PROFILE_PATH="/tmp/anaconda-firefox-profile"

# make sure the profile directory exists and is empty
if [ -d ${FIREFOX_PROFILE_PATH} ]
WEBUI_ADDRESS="127.0.0.1"
if [[ "$WEBUI_REMOTE" == "1" ]]
then
echo "Cleaning up existing Anaconda Firefox profile directory."
rm -rf ${FIREFOX_PROFILE_PATH}
WEBUI_ADDRESS="0.0.0.0"
fi
mkdir -p ${FIREFOX_PROFILE_PATH}

# populate the profile directory with our custom Firefox theme
# - theme id is passed as the second argument of this script
THEME_PATH="${FIREFOX_THEME_DIR}/${THEME_ID}"
echo "WEBUI_ADDRESS=$WEBUI_ADDRESS" > /tmp/webui-cockpit-ws.env
systemctl start webui-cockpit-ws

cp -a "${THEME_PATH}/." ${FIREFOX_PROFILE_PATH}

# FIXME: is this hardcoded resolution necessary ?
BROWSER="/usr/bin/firefox --new-instance --window-size 1024,768 --profile ${FIREFOX_PROFILE_PATH}"

# start browser in a temporary home dir, so that it does not interfere with your real one
BROWSER_HOME=$(mktemp --directory --tmpdir cockpit.desktop.XXXXXX)

WEBUI_ADDRESS="127.0.0.1"
if [[ "$WEBUI_REMOTE" == "1" ]]
then
WEBUI_ADDRESS="0.0.0.0"
/bin/sleep infinity &
BLOCK_ON_PID=$!
else
# prepare empty firefox profile dir with theme based on the passed profile id
FIREFOX_THEME_DIR="/usr/share/anaconda/firefox-theme"
FIREFOX_PROFILE_PATH="/tmp/anaconda-firefox-profile"

# make sure the profile directory exists and is empty
if [ -d ${FIREFOX_PROFILE_PATH} ]
then
echo "Cleaning up existing Anaconda Firefox profile directory."
rm -rf ${FIREFOX_PROFILE_PATH}
fi
mkdir -p ${FIREFOX_PROFILE_PATH}

# populate the profile directory with our custom Firefox theme
# - theme id is passed as the second argument of this script
THEME_PATH="${FIREFOX_THEME_DIR}/${THEME_ID}"

cp -a "${THEME_PATH}/." ${FIREFOX_PROFILE_PATH}

# FIXME: is this hardcoded resolution necessary ?
BROWSER="/usr/bin/firefox --new-instance --window-size 1024,768 --profile ${FIREFOX_PROFILE_PATH}"

# start browser in a temporary home dir, so that it does not interfere with your real one
BROWSER_HOME=$(mktemp --directory --tmpdir cockpit.desktop.XXXXXX)

# if we have netcat, use it for waiting until ws is up
if type nc >/dev/null 2>&1; then
for _ in `seq 10`; do
nc -z "$WEBUI_ADDRESS" 80 && break
sleep 0.5;
done
else
# otherwise, just wait a bit
sleep 3
fi

HOME="$BROWSER_HOME" MOZ_APP_TITLE="" MOZ_APP_REMOTINGNAME="liveinst" XDG_CURRENT_DESKTOP=GNOME MOZ_GTK_TITLEBAR_DECORATION=client $BROWSER http://"$WEBUI_ADDRESS""$URL_PATH" &
BLOCK_ON_PID=$!
fi

# forward parent stdin and stdout (from bridge) to cockpit-ws
# it pretty well does not matter which port we use in our own namespace, so use standard http
# disable /etc/cockpit/
XDG_CONFIG_DIRS="$BROWSER_HOME" COCKPIT_SUPERUSER="pkexec" /usr/libexec/cockpit-ws -p 80 -a "$WEBUI_ADDRESS" --no-tls --local-session=cockpit-bridge &
WS_PID=$!
exec > >(systemd-cat -t anaconda) 2>&1

# Cleanup function
cleanup() {
set +e
kill $WS_PID
wait $WS_PID
kill $B_PID
rm -rf $BROWSER_HOME
kill $BLOCK_ON_PID
[[ -n $BROWSER_HOME ]] && rm -rf $BROWSER_HOME
}
trap 'cleanup' EXIT INT QUIT PIPE

# if we have netcat, use it for waiting until ws is up
if type nc >/dev/null 2>&1; then
for _ in `seq 10`; do
nc -z "$WEBUI_ADDRESS" 80 && break
sleep 0.5;
done
else
# otherwise, just wait a bit
sleep 3
fi

HOME="$BROWSER_HOME" MOZ_APP_TITLE="" MOZ_APP_REMOTINGNAME="liveinst" XDG_CURRENT_DESKTOP=GNOME MOZ_GTK_TITLEBAR_DECORATION=client $BROWSER http://"$WEBUI_ADDRESS""$URL_PATH" &
B_PID=$!

wait $B_PID
wait $BLOCK_ON_PID

0 comments on commit 913cf8c

Please sign in to comment.