From b5fa01a1ab4a1beece2d1025c42624b7de3e560e Mon Sep 17 00:00:00 2001 From: Andrei Smaliak Date: Wed, 13 May 2026 16:54:22 +0400 Subject: [PATCH] =?UTF-8?q?fix=20the=20boot=20problem.=20=D1=83=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D1=8B=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - StandardInput=tty - TTYPath=/dev/tty7 - TTYReset=yes - TTYVHangup=yes --- stage_itscreen/stage_itscreen_install.sh | 71 ++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/stage_itscreen/stage_itscreen_install.sh b/stage_itscreen/stage_itscreen_install.sh index 4629eb8..8ab33e5 100755 --- a/stage_itscreen/stage_itscreen_install.sh +++ b/stage_itscreen/stage_itscreen_install.sh @@ -13,6 +13,7 @@ ITS_SESSION_SCRIPT="/usr/local/bin/itscreen-session" ITS_SESSION_LAUNCH="/usr/local/bin/itscreen-session-launch" ITS_X11_LAUNCHER="/usr/local/bin/itscreen-x11-launch" ITS_X11_CLEANUP="/usr/local/bin/itscreen-x11-cleanup" +ITS_BOOT_TRACE_SCRIPT="/usr/local/bin/itscreen-boot-trace" ITS_RECOVERY_SCRIPT="/usr/local/bin/itscreen-boot-recovery" ITS_SERVICE="itscreen-x11.service" ITS_RECOVERY_SERVICE="itscreen-x11-recovery.service" @@ -635,6 +636,65 @@ export XDG_RUNTIME_DIR=/run/itscreen/xdg exec /usr/bin/xinit /usr/local/bin/itscreen-session -- \ "$XORG_BIN" "$DISPLAY_NUM" "$VT_NAME" -keeptty -nolisten tcp -noreset +EOF + + write_file "$ITS_BOOT_TRACE_SCRIPT" 0755 root root <<'EOF' +#!/usr/bin/env bash +set -u + +PHASE="${1:-unspecified}" +STATE_DIR="/var/lib/itscreen" +LOG_DIR="${STATE_DIR}/logs" +TRACE_LOG="${LOG_DIR}/boot-trace.log" +ITS_SERVICE="itscreen-x11.service" +LIGHTDM_SERVICE="lightdm.service" +NM_CMD="/usr/bin/nm-online -s -q --timeout=45" + +timestamp_utc() { + date -u +'%F %T UTC' +} + +append_line() { + printf '%s\n' "$1" >>"$TRACE_LOG" 2>/dev/null || true +} + +append_cmd() { + local title="$1" + shift + append_line "### ${title}" + "$@" >>"$TRACE_LOG" 2>&1 || true + append_line "" +} + +append_shell() { + local title="$1" + local script="$2" + append_line "### ${title}" + bash -lc "$script" >>"$TRACE_LOG" 2>&1 || true + append_line "" +} + +mkdir -p "$LOG_DIR" >/dev/null 2>&1 || true +: >>"$TRACE_LOG" 2>/dev/null || true + +append_line "==== itscreen boot trace $(timestamp_utc) phase=${PHASE} ====" +append_line "hostname=$(hostname 2>/dev/null || true)" +append_line "boot_id=$(cat /proc/sys/kernel/random/boot_id 2>/dev/null || echo unavailable)" +append_line "kernel=$(uname -a 2>/dev/null || true)" +append_line "itscreen_active=$(systemctl is-active "$ITS_SERVICE" 2>/dev/null || true)" +append_line "itscreen_enabled=$(systemctl is-enabled "$ITS_SERVICE" 2>/dev/null || true)" +append_line "lightdm_active=$(systemctl is-active "$LIGHTDM_SERVICE" 2>/dev/null || true)" +append_line "lightdm_enabled=$(systemctl is-enabled "$LIGHTDM_SERVICE" 2>/dev/null || true)" +append_line "nm_wait_enabled=$(systemctl is-enabled NetworkManager-wait-online.service 2>/dev/null || true)" +append_line "nm_wait_active=$(systemctl is-active NetworkManager-wait-online.service 2>/dev/null || true)" +append_line "" + +append_shell "nm-online probe" "$NM_CMD; echo rc=\$?" +append_shell "DRM connector status" "if compgen -G '/sys/class/drm/*/status' >/dev/null 2>&1; then for f in /sys/class/drm/*/status; do printf '%s=%s\n' \"\$(basename \"\$(dirname \"\$f\")\")\" \"\$(tr -d '\\n' <\"\$f\" 2>/dev/null || true)\"; done; else echo unavailable; fi" +append_cmd "systemctl status itscreen-x11.service --no-pager -l" systemctl status "$ITS_SERVICE" --no-pager -l +append_cmd "systemctl status lightdm.service --no-pager -l" systemctl status "$LIGHTDM_SERVICE" --no-pager -l +append_shell "process snapshot" "ps aux | grep -E 'Xorg|xinit|openbox|itscreen' | grep -v grep || true" +append_shell "runtime directories" "ls -la /tmp/.X11-unix /run/itscreen /var/lib/itscreen/logs 2>/dev/null || true" EOF } @@ -656,6 +716,7 @@ FLAG_FILE="${STATE_DIR}/recovery.flag" RECOVERY_LOG="${LOG_DIR}/recovery.log" RECOVERY_JOURNAL="${LOG_DIR}/recovery-journal.log" RECOVERY_XORG="${LOG_DIR}/recovery-xorg.log" +BOOT_TRACE="/usr/local/bin/itscreen-boot-trace" XORG_LOG="/var/log/Xorg.0.log" timestamp_utc() { @@ -798,6 +859,7 @@ main() { : >>"$RECOVERY_LOG" 2>/dev/null || true log "Recovery invoked for ${ITS_SERVICE}; grace=${RECOVERY_GRACE_SECONDS}s poll=${RECOVERY_POLL_SECONDS}s" + [ -x "$BOOT_TRACE" ] && "$BOOT_TRACE" "recovery-start" || true while [ "$elapsed" -lt "$RECOVERY_GRACE_SECONDS" ]; do if appears_alive; then @@ -823,6 +885,7 @@ main() { fi log "itscreen-x11 still not healthy after grace period; collecting diagnostics and starting LightDM fallback" + [ -x "$BOOT_TRACE" ] && "$BOOT_TRACE" "recovery-fallback" || true save_diagnostics systemctl stop "$ITS_SERVICE" >/dev/null 2>&1 || true systemctl reset-failed "$ITS_SERVICE" >/dev/null 2>&1 || true @@ -868,19 +931,18 @@ RuntimeDirectory=itscreen RuntimeDirectoryMode=0755 Environment=ITSCREEN_DISPLAY=:0 Environment=ITSCREEN_VT=vt7 +ExecStartPre=-/usr/local/bin/itscreen-boot-trace pre-start ExecStartPre=/usr/bin/nm-online -s -q --timeout=45 # Monitor presence is not required for startup; always attempt the dedicated X11 launch flow, including headless mode. ExecStartPre=/usr/local/bin/itscreen-x11-cleanup ExecStart=/usr/local/bin/itscreen-x11-launch +ExecStartPost=-/usr/local/bin/itscreen-boot-trace start-post +ExecStopPost=-/usr/local/bin/itscreen-boot-trace stop-post ExecStopPost=/usr/local/bin/itscreen-x11-cleanup Restart=always RestartSec=2 TimeoutStopSec=15 KillMode=mixed -StandardInput=tty -TTYPath=/dev/tty7 -TTYReset=yes -TTYVHangup=yes [Install] WantedBy=multi-user.target @@ -975,6 +1037,7 @@ post_install_self_test() { "$ITS_SESSION_LAUNCH" \ "$ITS_X11_LAUNCHER" \ "$ITS_X11_CLEANUP" \ + "$ITS_BOOT_TRACE_SCRIPT" \ "$ITS_RECOVERY_SCRIPT"; do if [[ ! -x "$missing_path" ]]; then die "Required launcher script missing or not executable: ${missing_path}"