Files
aitbc/scripts/sync/sync_detector.sh
aitbc 3b8249d299 refactor: comprehensive scripts directory reorganization by functionality
Scripts Directory Reorganization - Complete:
 FUNCTIONAL ORGANIZATION: Scripts sorted into 8 logical categories
- github/: GitHub and Git operations (6 files)
- sync/: Synchronization and data replication (4 files)
- security/: Security and audit operations (2 files)
- monitoring/: System and service monitoring (6 files)
- maintenance/: System maintenance and cleanup (4 files)
- deployment/: Deployment and provisioning (11 files)
- testing/: Testing and quality assurance (13 files)
- utils/: Utility scripts and helpers (47 files)

 ROOT DIRECTORY CLEANED: Only README.md remains in scripts root
- scripts/README.md: Main documentation
- scripts/SCRIPTS_ORGANIZATION.md: Complete organization guide
- All functional scripts moved to appropriate subdirectories

 SCRIPTS CATEGORIZATION:
📁 GitHub Operations: PR resolution, repository management, Git workflows
📁 Synchronization: Bulk sync, fast sync, sync detection, SystemD sync
📁 Security: Security audits, monitoring, vulnerability scanning
📁 Monitoring: Health checks, log monitoring, network monitoring, production monitoring
📁 Maintenance: Cleanup operations, performance tuning, weekly maintenance
📁 Deployment: Release building, node provisioning, DAO deployment, production deployment
📁 Testing: E2E testing, workflow testing, QA cycles, service testing
📁 Utilities: System management, setup scripts, helpers, tools

 ORGANIZATION BENEFITS:
- Better Navigation: Scripts grouped by functionality
- Easier Maintenance: Related scripts grouped together
- Scalable Structure: Easy to add new scripts to appropriate categories
- Clear Documentation: Comprehensive organization guide with descriptions
- Improved Workflow: Quick access to relevant scripts by category

 DOCUMENTATION ENHANCED:
- SCRIPTS_ORGANIZATION.md: Complete directory structure and usage guide
- Quick Reference: Common script usage examples
- Script Descriptions: Purpose and functionality for each script
- Maintenance Guidelines: How to keep organization current

DIRECTORY STRUCTURE:
📁 scripts/
├── README.md (Main documentation)
├── SCRIPTS_ORGANIZATION.md (Organization guide)
├── github/ (6 files - GitHub operations)
├── sync/ (4 files - Synchronization)
├── security/ (2 files - Security)
├── monitoring/ (6 files - Monitoring)
├── maintenance/ (4 files - Maintenance)
├── deployment/ (11 files - Deployment)
├── testing/ (13 files - Testing)
├── utils/ (47 files - Utilities)
├── ci/ (existing - CI/CD)
├── deployment/ (existing - legacy deployment)
├── development/ (existing - Development tools)
├── monitoring/ (existing - Legacy monitoring)
├── services/ (existing - Service management)
├── testing/ (existing - Legacy testing)
├── utils/ (existing - Legacy utilities)
├── workflow/ (existing - Workflow automation)
└── workflow-openclaw/ (existing - OpenClaw workflows)

RESULT: Successfully reorganized 27 unorganized scripts into 8 functional categories, creating a clean, maintainable, and well-documented scripts directory structure with comprehensive organization guide.
2026-03-30 17:13:27 +02:00

53 lines
1.5 KiB
Bash

#!/bin/bash
GENESIS_NODE="10.1.223.40"
GENESIS_PORT="8006"
LOCAL_PORT="8006"
MAX_SYNC_DIFF=100
LOG_FILE="/var/log/aitbc/sync_detector.log"
log_sync() {
echo "[$(date)] $1" >> "$LOG_FILE"
}
check_sync_diff() {
local_height=$(curl -s "http://localhost:$LOCAL_PORT/rpc/head" | jq -r .height 2>/dev/null || echo "0")
genesis_height=$(curl -s "http://$GENESIS_NODE:$GENESIS_PORT/rpc/head" | jq -r .height 2>/dev/null || echo "0")
if [ "$local_height" -eq 0 ] || [ "$genesis_height" -eq 0 ]; then
log_sync "ERROR: Cannot get blockchain heights"
return 1
fi
diff=$((genesis_height - local_height))
echo "$diff"
}
main() {
log_sync "Starting sync check"
diff=$(check_sync_diff)
log_sync "Sync difference: $diff blocks"
if [ "$diff" -gt "$MAX_SYNC_DIFF" ]; then
log_sync "Large sync difference detected ($diff > $MAX_SYNC_DIFF), initiating bulk sync"
/opt/aitbc/scripts/bulk_sync.sh >> "$LOG_FILE" 2>&1
new_diff=$(check_sync_diff)
log_sync "Post-sync difference: $new_diff blocks"
if [ "$new_diff" -le "$MAX_SYNC_DIFF" ]; then
log_sync "Bulk sync successful"
else
log_sync "Bulk sync partially successful, may need additional runs"
fi
else
log_sync "Sync difference is normal ($diff <= $MAX_SYNC_DIFF)"
fi
log_sync "Sync check completed"
}
main
EOF && chmod +x /opt/aitbc/scripts/sync_detector.sh && echo "✅ Sync detector script fixed and made executable"