diff --git a/stage_z2m/VENDORED_Z2M.md b/stage_z2m/VENDORED_Z2M.md index 31c0e2d..aa03ea2 100644 --- a/stage_z2m/VENDORED_Z2M.md +++ b/stage_z2m/VENDORED_Z2M.md @@ -1,25 +1,39 @@ # Vendored Zigbee2MQTT Bundle -This directory contains a vendored Zigbee2MQTT source archive used by `stage_z2m_03_code.sh`. +This directory contains a vendored Zigbee2MQTT bundle used by `stage_z2m_03_code.sh`. Default behavior: -- `stage_z2m_03_code.sh` first looks for a bundled Zigbee2MQTT source archive or directory in `stage_z2m/` +- `stage_z2m_03_code.sh` first looks for a bundled Zigbee2MQTT archive or directory in `stage_z2m/` - network download is disabled by default - network fallback is available only when `Z2M_ALLOW_NETWORK_FALLBACK=1` +Bundle requirement: + +- prefer a prebuilt bundle that already contains `dist/` +- this avoids running `pnpm exec tsc` on the Edge device +- some Edge ARM64 targets can fail during TypeScript compilation with `SIGILL`, while runtime works fine with a prebuilt `dist/` +- if `dist/controller.js` and `dist/util/onboarding.js` are present, `stage_z2m` skips the compile step and only writes the runtime hash + Current vendored archive: ```text file : stage_z2m/zigbee2mqtt.tar.gz -source : https://codeload.github.com/Koenkk/zigbee2mqtt/tar.gz/refs/heads/master +source : prebuilt bundle derived from https://codeload.github.com/Koenkk/zigbee2mqtt/tar.gz/refs/heads/master version : 2.9.2 -sha256 : 3a540374330bcbf1513f05485e84d507e768936f592ba4c4b22c694f201a4ae9 +sha256 : f5fddb095c4aecf002602e0aa4096a9144b2394e59b7a25647c1d8b605d0cca1 ``` +Important: + +- the current archive includes prebuilt `dist/` +- this lets Edge skip the local TypeScript compile step +- on devices where `tsc` crashes, this is the required production format + Update workflow: -1. Download the new archive snapshot from the desired ref or tag. -2. Replace `stage_z2m/zigbee2mqtt.tar.gz`. -3. Update the `version`, `source`, and `sha256` fields in this file. -4. Re-test `stage_z2m` on Edge before using it in production. +1. Prepare a Zigbee2MQTT bundle from the desired ref or tag. +2. Ensure the bundle contains compiled `dist/`. +3. Replace `stage_z2m/zigbee2mqtt.tar.gz`. +4. Update the `version`, `source`, and `sha256` fields in this file. +5. Re-test `stage_z2m` on Edge before using it in production. diff --git a/stage_z2m/stage_z2m_lib.sh b/stage_z2m/stage_z2m_lib.sh index 225a5c8..e3c33ba 100755 --- a/stage_z2m/stage_z2m_lib.sh +++ b/stage_z2m/stage_z2m_lib.sh @@ -416,6 +416,28 @@ write_if_changed() { mv -f "$tmp" "$target" } +verify_systemd_unit_file() { + local unit_name="$1" + local unit_path="$2" + + [ -f "$unit_path" ] || die "Expected systemd unit file is missing: ${unit_path}" + + if command -v systemd-analyze >/dev/null 2>&1; then + systemd-analyze verify "$unit_path" >/dev/null 2>&1 \ + || die "systemd-analyze verify failed for ${unit_name} (${unit_path})" + fi +} + +verify_systemd_unit_registration() { + local unit_name="$1" + + require_cmd systemctl + systemctl list-unit-files "$unit_name" --no-legend 2>/dev/null \ + | awk '{print $1}' \ + | grep -qx "$unit_name" \ + || die "systemd did not register unit after daemon-reload: ${unit_name}" +} + safe_inplace_edit() { local target="$1" local tmp @@ -839,12 +861,17 @@ build_z2m() { export CI=1 log_build_versions "$build_user" build_snapshot + + if [ -f "${Z2M_DIR}/dist/controller.js" ] && [ -f "${Z2M_DIR}/dist/util/onboarding.js" ]; then + log "Detected prebuilt Zigbee2MQTT dist/ bundle -> skipping TypeScript compilation on edge" + else run_logged_build_step \ "tsc" \ "$TSC_TIMEOUT_SECONDS" \ "$TSC_LOG" \ sudo -u "$build_user" env CI=1 COREPACK_ENABLE_DOWNLOAD_PROMPT=0 nice -n 5 bash -lc "cd '$Z2M_DIR' && pnpm exec tsc --pretty false" \ || die "TypeScript build step failed" + fi run_logged_build_step \ "writehash" \ "$WRITEHASH_TIMEOUT_SECONDS" \ @@ -1015,6 +1042,7 @@ LimitNOFILE=65536 [Install] WantedBy=multi-user.target +Alias=iomatex-z2m.service EOF write_if_changed /usr/local/sbin/iomatex-z2m-healthcheck.sh 0755 root root </dev/null 2>&1 || true - systemctl enable iomatex-z2m-healthcheck.timer >/dev/null 2>&1 || true - systemctl enable iomatex-z2m-web.service >/dev/null 2>&1 || true + verify_systemd_unit_registration "zigbee2mqtt.service" + verify_systemd_unit_registration "iomatex-z2m-healthcheck.service" + verify_systemd_unit_registration "iomatex-z2m-healthcheck.timer" + verify_systemd_unit_registration "iomatex-z2m-web.service" + systemctl enable zigbee2mqtt + systemctl enable iomatex-z2m-healthcheck.timer + systemctl enable iomatex-z2m-web.service systemctl restart zigbee2mqtt || systemctl start zigbee2mqtt systemctl restart iomatex-z2m-web.service || systemctl start iomatex-z2m-web.service systemctl start iomatex-z2m-healthcheck.timer || true @@ -1348,6 +1386,8 @@ MQTT base_topic : ${MQTT_BASE_TOPIC} Public Web UI : http://:${WEB_PORT_PUBLIC} Internal frontend : http://127.0.0.1:${WEB_PORT_INTERNAL} Help : iomatex-help-z2m (or iomatex-z2m) +Primary systemd unit : zigbee2mqtt.service +Alias systemd unit : iomatex-z2m.service Logs : journalctl -u zigbee2mqtt -f Web gateway logs : journalctl -u iomatex-z2m-web -f Critical state files : ${Z2M_DATA_DIR}/configuration.yaml, ${Z2M_DATA_DIR}/database.db, ${Z2M_DATA_DIR}/coordinator_backup.json, ${Z2M_DATA_DIR}/state.json diff --git a/stage_z2m/zigbee2mqtt.tar.gz b/stage_z2m/zigbee2mqtt.tar.gz index bc8390f..7328049 100644 Binary files a/stage_z2m/zigbee2mqtt.tar.gz and b/stage_z2m/zigbee2mqtt.tar.gz differ