stage_ui updater fix

This commit is contained in:
Andrei Smaliak 2026-07-08 12:14:25 +02:00
parent de5614358a
commit 60a8db49ea
3 changed files with 50 additions and 4 deletions

View File

@ -31,6 +31,7 @@ FRONTEND_DIR="${APP_DIR}/frontend"
MODBUS_PROFILES_DIR="${APP_DIR}/modbus_profiles" MODBUS_PROFILES_DIR="${APP_DIR}/modbus_profiles"
SERVICE_NAME="iomatex-console.service" SERVICE_NAME="iomatex-console.service"
LEGACY_SERVICE_NAME="iomatex-webipc.service" LEGACY_SERVICE_NAME="iomatex-webipc.service"
SERVICE_UNIT_PATH="/etc/systemd/system/${SERVICE_NAME}"
CFG_PATH="/etc/iomatex/console.json" CFG_PATH="/etc/iomatex/console.json"
SRC_LOGO="${LOGO_SOURCE:-$SCRIPT_DIR/iomatex_logo_source.png}" SRC_LOGO="${LOGO_SOURCE:-$SCRIPT_DIR/iomatex_logo_source.png}"
SRC_GBOX="${GBOX_SOURCE:-$SCRIPT_DIR/g-box.png}" SRC_GBOX="${GBOX_SOURCE:-$SCRIPT_DIR/g-box.png}"
@ -170,6 +171,21 @@ remove_if_exists() {
return 0 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 step_n=0
TOTAL_STEPS=10 TOTAL_STEPS=10
@ -279,7 +295,8 @@ fav.save(fav_out, format="PNG")
PY PY
step "Install systemd service" step "Install systemd service"
cat > "/etc/systemd/system/${SERVICE_NAME}" <<UNIT prepare_systemd_unit_path "$SERVICE_UNIT_PATH" "$SERVICE_NAME"
cat > "$SERVICE_UNIT_PATH" <<UNIT
[Unit] [Unit]
Description=IOMATEX Console Core Description=IOMATEX Console Core
After=network-online.target After=network-online.target
@ -297,6 +314,14 @@ Group=root
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
UNIT UNIT
if [ ! -s "$SERVICE_UNIT_PATH" ]; then
echo "ERROR: failed to write non-empty systemd unit: $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" echo "[8/8] Remove optional mDNS alias artifacts"
remove_if_exists /etc/avahi/services/iomatex-console.service remove_if_exists /etc/avahi/services/iomatex-console.service
@ -340,6 +365,9 @@ if ! wait_for_local_http; then
rollback_deploy rollback_deploy
exit 1 exit 1
fi 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" step "Summary"
echo "Web UI: http://<EDGE-IP>" echo "Web UI: http://<EDGE-IP>"

View File

@ -69,6 +69,10 @@ unit_enabled_state() {
systemctl is-enabled "$1" 2>/dev/null || true systemctl is-enabled "$1" 2>/dev/null || true
} }
unit_fragment_path() {
systemctl show -p FragmentPath --value "$1" 2>/dev/null || true
}
port_listening() { port_listening() {
ss -ltn 2>/dev/null | awk '{print $4}' | grep -Eq "(^|:)$1$" ss -ltn 2>/dev/null | awk '{print $4}' | grep -Eq "(^|:)$1$"
} }
@ -362,6 +366,16 @@ check_console() {
console_port="$(read_console_port)" console_port="$(read_console_port)"
if unit_exists "iomatex-console.service"; then 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 if unit_active "iomatex-console.service"; then
pass "iomatex-console.service active" pass "iomatex-console.service active"
else else

View File

@ -1042,7 +1042,8 @@ fi
console_ready=0 console_ready=0
if systemctl is-active --quiet iomatex-console.service; then if systemctl is-active --quiet iomatex-console.service; then
if command -v curl >/dev/null 2>&1; 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 console_ready=1
fi fi
elif command -v python3 >/dev/null 2>&1; then elif command -v python3 >/dev/null 2>&1; then
@ -1051,8 +1052,11 @@ import sys
import urllib.request import urllib.request
port = sys.argv[1] port = sys.argv[1]
try: try:
with urllib.request.urlopen(f"http://127.0.0.1:{port}/api/status", timeout=2) as response: for path in ("/", "/api/auth/session"):
raise SystemExit(0 if response.status == 200 else 1) 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: except Exception:
raise SystemExit(1) raise SystemExit(1)
PY PY