plc-checkweigher 1.32.1 → 1.32.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1088,18 +1088,56 @@ SMBC
1088
1088
  echo ""
1089
1089
  fi
1090
1090
 
1091
- # ── 8. plc_live.json staleness ────────────────────────────────────────
1091
+ # ── 8. Live state file (/tmp/plc_live.json) service-aware repair ─────
1092
+ # The watcher writes this file continuously. If it is missing or stale
1093
+ # we decide the fix by the service state, not by the file alone:
1094
+ # • watcher inactive → start it
1095
+ # • watcher active + missing → stuck before first write → restart
1096
+ # • watcher active + stale → lost PLC / stuck loop → restart
1097
+ # After any restart we wait briefly and confirm the file reappears.
1092
1098
  spin_start "Live state file (/tmp/plc_live.json)"
1093
- if [[ -f "/tmp/plc_live.json" ]]; then
1094
- _AGE=$(( $(date +%s) - $(stat -c %Y /tmp/plc_live.json 2>/dev/null || echo 0) ))
1095
- if [[ "${_AGE:-0}" -gt 10 ]]; then
1096
- ffix_warn "plc_live.json is ${_AGE}s old — watcher may be stuck or offline"
1097
- flog "WARN: plc_live.json stale (${_AGE}s old)"
1099
+ _LIVE="/tmp/plc_live.json"
1100
+ _WATCHER_ACTIVE=0
1101
+ systemctl is-active --quiet plc_watcher 2>/dev/null && _WATCHER_ACTIVE=1
1102
+
1103
+ _LIVE_PROBLEM="" # empty = healthy
1104
+ if [[ -f "$_LIVE" ]]; then
1105
+ _AGE=$(( $(date +%s) - $(stat -c %Y "$_LIVE" 2>/dev/null || echo 0) ))
1106
+ [[ "${_AGE:-0}" -gt 10 ]] && _LIVE_PROBLEM="stale (${_AGE}s old)"
1107
+ else
1108
+ _LIVE_PROBLEM="missing"
1109
+ fi
1110
+
1111
+ if [[ -z "$_LIVE_PROBLEM" ]]; then
1112
+ ffix_info "plc_live.json updated ${_AGE}s ago (OK)"
1113
+ elif [[ $_WATCHER_ACTIVE -eq 0 ]]; then
1114
+ ffix_warn "plc_live.json ${_LIVE_PROBLEM} — plc_watcher is not running"
1115
+ flog "WARN: live state ${_LIVE_PROBLEM}; plc_watcher inactive"
1116
+ spin_start "Starting plc_watcher"
1117
+ sudo systemctl start plc_watcher 2>/dev/null || true
1118
+ sleep 4
1119
+ if [[ -f "$_LIVE" ]]; then
1120
+ ffix_ok "plc_watcher started — live state now being written"
1098
1121
  else
1099
- ffix_info "plc_live.json updated ${_AGE}s ago (OK)"
1122
+ ffix_err "plc_watcher started but live state still missing — check: journalctl -u plc_watcher"
1100
1123
  fi
1101
1124
  else
1102
- ffix_info "plc_live.json absent (normal created when watcher connects)"
1125
+ # Service is up but the file is missing/stale → watcher stuck. Restart.
1126
+ ffix_warn "plc_live.json ${_LIVE_PROBLEM} while plc_watcher is running — restarting watcher"
1127
+ flog "WARN: live state ${_LIVE_PROBLEM}; watcher active → restart"
1128
+ spin_start "Restarting plc_watcher"
1129
+ sudo systemctl restart plc_watcher 2>/dev/null || true
1130
+ sleep 4
1131
+ if [[ -f "$_LIVE" ]]; then
1132
+ _AGE2=$(( $(date +%s) - $(stat -c %Y "$_LIVE" 2>/dev/null || echo 0) ))
1133
+ if [[ "${_AGE2:-99}" -le 10 ]]; then
1134
+ ffix_ok "Watcher restarted — live state fresh (${_AGE2}s old)"
1135
+ else
1136
+ ffix_warn "Watcher restarted but live state still stale — PLC may be unreachable"
1137
+ fi
1138
+ else
1139
+ ffix_err "Watcher restarted but live state still missing — check: journalctl -u plc_watcher"
1140
+ fi
1103
1141
  fi
1104
1142
 
1105
1143
  # ── 9. reader script path ─────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plc-checkweigher",
3
- "version": "1.32.1",
3
+ "version": "1.32.3",
4
4
  "description": "One-command installer for the PLC Check-Weigher system on Raspberry Pi (PREEMPT_RT kernel, Python stack, WiFi, SMB, systemd RT services)",
5
5
  "scripts": {
6
6
  "postinstall": "node bin/cli.js"