diff --git a/stage_ui/ui_installer.sh b/stage_ui/ui_installer.sh index 87857b2..0ffd545 100644 --- a/stage_ui/ui_installer.sh +++ b/stage_ui/ui_installer.sh @@ -31,6 +31,7 @@ FRONTEND_DIR="${APP_DIR}/frontend" MODBUS_PROFILES_DIR="${APP_DIR}/modbus_profiles" SERVICE_NAME="iomatex-console.service" LEGACY_SERVICE_NAME="iomatex-webipc.service" +SERVICE_UNIT_PATH="/etc/systemd/system/${SERVICE_NAME}" CFG_PATH="/etc/iomatex/console.json" SRC_LOGO="${LOGO_SOURCE:-$SCRIPT_DIR/iomatex_logo_source.png}" SRC_GBOX="${GBOX_SOURCE:-$SCRIPT_DIR/g-box.png}" @@ -170,6 +171,21 @@ remove_if_exists() { return 0 } +prepare_systemd_unit_path() { + local unit_path="$1" + local unit_name="$2" + local broken_path="" + + systemctl_try unmask "$unit_name" + if [ -L "$unit_path" ] && [ "$(readlink "$unit_path" 2>/dev/null || true)" = "/dev/null" ]; then + rm -f "$unit_path" + elif [ -e "$unit_path" ] && [ ! -s "$unit_path" ]; then + broken_path="${unit_path}.broken.${ts}" + mv "$unit_path" "$broken_path" + echo "Recovered empty systemd unit: moved ${unit_path} to ${broken_path}" + fi +} + step_n=0 TOTAL_STEPS=10 @@ -279,7 +295,8 @@ fav.save(fav_out, format="PNG") PY step "Install systemd service" -cat > "/etc/systemd/system/${SERVICE_NAME}" < "$SERVICE_UNIT_PATH" <&2 + exit 1 +fi +if [ -L "$SERVICE_UNIT_PATH" ] && [ "$(readlink "$SERVICE_UNIT_PATH" 2>/dev/null || true)" = "/dev/null" ]; then + echo "ERROR: systemd unit is still masked: $SERVICE_UNIT_PATH" >&2 + exit 1 +fi echo "[8/8] Remove optional mDNS alias artifacts" remove_if_exists /etc/avahi/services/iomatex-console.service @@ -340,6 +365,9 @@ if ! wait_for_local_http; then rollback_deploy exit 1 fi +if [ -x /usr/local/sbin/iomatex-ap-refresh-landing ]; then + /usr/local/sbin/iomatex-ap-refresh-landing >/dev/null 2>&1 || true +fi step "Summary" echo "Web UI: http://" diff --git a/stage_validation/iomatex-postinstall-selftest.sh b/stage_validation/iomatex-postinstall-selftest.sh index e9f6d4a..33656b1 100755 --- a/stage_validation/iomatex-postinstall-selftest.sh +++ b/stage_validation/iomatex-postinstall-selftest.sh @@ -69,6 +69,10 @@ unit_enabled_state() { systemctl is-enabled "$1" 2>/dev/null || true } +unit_fragment_path() { + systemctl show -p FragmentPath --value "$1" 2>/dev/null || true +} + port_listening() { ss -ltn 2>/dev/null | awk '{print $4}' | grep -Eq "(^|:)$1$" } @@ -362,6 +366,16 @@ check_console() { console_port="$(read_console_port)" if unit_exists "iomatex-console.service"; then + local enabled_state="" + local fragment_path="" + enabled_state="$(unit_enabled_state "iomatex-console.service")" + fragment_path="$(unit_fragment_path "iomatex-console.service")" + if [[ "$enabled_state" == "masked" ]]; then + fail "iomatex-console.service is masked" + fi + if [[ -n "$fragment_path" && -e "$fragment_path" && ! -s "$fragment_path" ]]; then + fail "iomatex-console.service unit file is empty: ${fragment_path}" + fi if unit_active "iomatex-console.service"; then pass "iomatex-console.service active" else diff --git a/stage_wifi/stage_wifi_install.sh b/stage_wifi/stage_wifi_install.sh index f6676a4..f9b2ba6 100644 --- a/stage_wifi/stage_wifi_install.sh +++ b/stage_wifi/stage_wifi_install.sh @@ -1042,7 +1042,8 @@ fi console_ready=0 if systemctl is-active --quiet iomatex-console.service; then if command -v curl >/dev/null 2>&1; then - if curl -m 2 -fsS "http://127.0.0.1:${CONSOLE_PORT}/api/status" >/dev/null 2>&1; then + if curl -m 2 -fsS "http://127.0.0.1:${CONSOLE_PORT}/" >/dev/null 2>&1 \ + && curl -m 2 -fsS "http://127.0.0.1:${CONSOLE_PORT}/api/auth/session" >/dev/null 2>&1; then console_ready=1 fi elif command -v python3 >/dev/null 2>&1; then @@ -1051,8 +1052,11 @@ import sys import urllib.request port = sys.argv[1] try: - with urllib.request.urlopen(f"http://127.0.0.1:{port}/api/status", timeout=2) as response: - raise SystemExit(0 if response.status == 200 else 1) + for path in ("/", "/api/auth/session"): + with urllib.request.urlopen(f"http://127.0.0.1:{port}{path}", timeout=2) as response: + if response.status != 200: + raise SystemExit(1) + raise SystemExit(0) except Exception: raise SystemExit(1) PY