Root cause analysis of the 2026-07-20 redundancy incident: 1. No single-source-of-truth rule -> same file legitimately lived in 4+ locations, diverging silently 2. Relative path resolution (Path(__file__).parent/'data') -> each hardlinked copy of mofin_db.py pointed to a DIFFERENT database 3. 'Backup habit' left .bak/legacy files in production dirs, which monitoring then scanned and reported as false alarms 4. Half-done migrations: DB tables created but old JSON writers/readers stayed (price_events), old files stayed 5. Dead modules never got buried: xiaoguo 'dead' but bot ran 8 days as root eating 2.5GB 6. Monitoring checked 'does it exist' not 'is it alive' -> stale file mtime reported as 'pipeline stalled 14 days' (false alarm) 7. No 'system hygiene' as a check category at all Prevention implemented: - dev-spec.md v2.0: 五条红线 -> 十条红线 #6 single source of truth (hardlink only, no independent copies) #7 absolute data paths only (no __file__-relative data resolution) #8 no backups/legacy in production data dirs (archive immediately) #9 dead module burial checklist (6 mandatory steps) #10 monitor liveness (DB table freshness) not existence - File Location Constitution: canonical location per content type - NEW system_hygiene_audit.py: weekly Monday 07:30 cron checking diverged copies / broken hardlinks / zombie processes / orphan data files / dead cron scripts / DB freshness -> hygiene_report.json + XMPP - specs/hygiene.json: module spec per red line #1 - Verified: audit found 5 real issues on first run, all fixed, re-run clean
27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
import subprocess
|
||
|
||
# 更新 crontab:cron_to_xmpp.py 改指 deploy 路径(web-dashboard 副本已归档)
|
||
r = subprocess.run(['crontab', '-l'], capture_output=True, text=True)
|
||
lines = r.stdout.splitlines()
|
||
new_lines = []
|
||
for line in lines:
|
||
if 'cron_to_xmpp.py' in line and 'web-dashboard' in line:
|
||
new_line = line.replace(
|
||
'cd /home/hmo/web-dashboard && python3 cron_to_xmpp.py',
|
||
'cd /home/hmo/MoFin/deploy/profile-scripts && python3 cron_to_xmpp.py')
|
||
new_lines.append(new_line)
|
||
print('CHANGED:')
|
||
print(' old:', line)
|
||
print(' new:', new_line)
|
||
else:
|
||
new_lines.append(line)
|
||
|
||
p = subprocess.run(['crontab', '-'], input='\n'.join(new_lines) + '\n',
|
||
capture_output=True, text=True)
|
||
print('crontab updated, rc=', p.returncode)
|
||
|
||
# 验证 deploy 版本能跑(dry check: import + 语法)
|
||
r2 = subprocess.run(
|
||
"cd /home/hmo/MoFin/deploy/profile-scripts && python3 -c 'import ast; ast.parse(open(\"cron_to_xmpp.py\").read()); print(\"syntax OK\")'",
|
||
shell=True, capture_output=True, text=True, timeout=10)
|
||
print(r2.stdout.strip() or r2.stderr.strip()[:200]) |