# Troubleshooting Guide This comprehensive guide helps diagnose and resolve common issues with Readur installations and operations. ## Quick Diagnosis ### Health Check Script ```bash #!/bin/bash # health-check.sh echo "=== Readur System Health Check ===" echo "Timestamp: $(date)" echo "" # Check services echo "Service Status:" systemctl is-active readur && echo "✓ Readur: Running" || echo "✗ Readur: Stopped" systemctl is-active postgresql && echo "✓ PostgreSQL: Running" || echo "✗ PostgreSQL: Stopped" systemctl is-active nginx && echo "✓ Nginx: Running" || echo "✗ Nginx: Stopped" echo "" # Check connectivity echo "Connectivity:" curl -s -o /dev/null -w "✓ Web Server: %{http_code}\n" http://localhost:8080/health pg_isready -q && echo "✓ Database: Connected" || echo "✗ Database: Not reachable" echo "" # Check disk space echo "Disk Usage:" df -h | grep -E "Filesystem|/var|/uploads" echo "" # Check recent errors echo "Recent Errors (last 10):" journalctl -u readur --no-pager -n 10 | grep -i error || echo "No recent errors" ``` ## Common Issues and Solutions ### Installation Issues #### Problem: Docker container fails to start **Symptoms:** - Container exits immediately - Status shows "Exited (1)" **Diagnosis:** ```bash # Check container logs docker logs readur-app # Check detailed events docker events --filter container=readur-app # Inspect container configuration docker inspect readur-app ``` **Solutions:** **Port conflict:** Check if the port is already in use and resolve the conflict. ```bash # Check if port is in use sudo lsof -i :8080 # Change port in docker-compose.yml ports: - "8081:8080" # Use different external port ``` **Database connection failure:** Verify that the database service is running and accessible. ```bash # Verify database is running docker ps | grep postgres # Test database connection docker exec readur-app psql $DATABASE_URL -c "SELECT 1" # Fix connection string export DATABASE_URL="postgresql://readur:password@db:5432/readur" ``` **Permission issues:** Resolve file and directory permission problems that prevent the container from accessing required resources. ```bash # Fix volume permissions sudo chown -R 1000:1000 ./uploads sudo chmod -R 755 ./uploads # Run with proper user docker run --user $(id -u):$(id -g) readur:latest ``` #### Problem: Build fails with Rust compilation errors **Solutions:** **Update Rust toolchain:** Ensure you're using the latest stable Rust version to avoid compatibility issues. ```bash rustup update rustup default stable cargo clean cargo build --release ``` **Clear build cache:** Remove stale build artifacts that may be causing compilation problems. ```bash rm -rf target/ rm Cargo.lock cargo build --release ``` **Install missing dependencies:** Ensure all required system dependencies are installed for compilation. ```bash # Ubuntu/Debian sudo apt-get install build-essential pkg-config libssl-dev # macOS brew install openssl pkg-config # Set environment variables export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig" ``` ### Database Issues #### Problem: Database connection refused **Diagnosis:** ```bash # Test direct connection psql -h localhost -p 5432 -U readur -d readur # Check PostgreSQL logs sudo journalctl -u postgresql -n 50 # Verify PostgreSQL is listening sudo netstat -tlnp | grep 5432 ``` **Solutions:** **PostgreSQL not running:** Start the PostgreSQL service and ensure it's configured to start automatically. ```bash # Start PostgreSQL sudo systemctl start postgresql # Enable auto-start sudo systemctl enable postgresql ``` **Authentication failure:** Configure PostgreSQL to accept connections from the Readur application. ```bash # Edit pg_hba.conf sudo nano /etc/postgresql/15/main/pg_hba.conf # Add/modify line: local all readur md5 host all readur 127.0.0.1/32 md5 # Reload configuration sudo systemctl reload postgresql ``` **Database doesn't exist:** Create the required database and user with appropriate permissions. ```bash # Create database and user sudo -u postgres psql < 1; -- Remove duplicates keeping newest DELETE FROM documents a USING documents b WHERE a.id < b.id AND a.file_hash = b.file_hash; ``` ### OCR Processing Issues #### Problem: OCR queue stuck **Diagnosis:** ```bash # Check queue status psql -U readur -d readur <= max_retries; EOF ``` #### Problem: OCR produces garbled text **Solutions:** **Wrong language configuration:** Verify and correct the OCR language settings for better text recognition. ```bash # Check current language echo $OCR_LANGUAGE # Update for document psql -U readur -d readur < console.log('Connected'); ws.onerror = (e) => console.error('Error:', e); ws.onmessage = (e) => console.log('Message:', e.data); ``` **Solutions:** **Proxy configuration:** Configure your reverse proxy to properly handle WebSocket connections. ```nginx # nginx.conf location /ws { proxy_pass http://localhost:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 86400; } ``` **Firewall rules:** Ensure firewall settings allow WebSocket connections on the required ports. ```bash # Allow WebSocket port sudo ufw allow 8080/tcp # Check iptables sudo iptables -L -n | grep 8080 ``` ## Debug Logging ### Enable Detailed Logging ```bash # Set environment variables export RUST_LOG=debug export RUST_BACKTRACE=full # Or in configuration LOG_LEVEL=debug LOG_FORMAT=json LOG_TO_FILE=true LOG_FILE_PATH=/var/log/readur/debug.log ``` ### Analyze Logs ```bash # Filter by severity grep -E "ERROR|WARN" /var/log/readur/app.log # Track specific request grep "request_id=req_123" /var/log/readur/app.log # Parse JSON logs jq '.level == "error"' /var/log/readur/app.json # Real-time monitoring tail -f /var/log/readur/app.log | grep --line-buffered ERROR ``` ## Performance Profiling ### CPU Profiling ```bash # Using perf perf record -g -p $(pgrep readur) perf report # Using flamegraph cargo install flamegraph cargo flamegraph --bin readur ``` ### Memory Profiling ```bash # Using valgrind valgrind --leak-check=full --show-leak-kinds=all ./readur # Using heaptrack heaptrack ./readur heaptrack_gui heaptrack.readur.*.gz ``` ### Database Query Analysis ```sql -- Enable query logging ALTER SYSTEM SET log_statement = 'all'; ALTER SYSTEM SET log_duration = on; SELECT pg_reload_conf(); -- Check slow queries SELECT query, mean_exec_time, calls FROM pg_stat_statements WHERE mean_exec_time > 1000 ORDER BY mean_exec_time DESC LIMIT 10; ``` ## Recovery Procedures ### Emergency Database Recovery ```bash #!/bin/bash # emergency-db-recovery.sh # Stop application systemctl stop readur # Backup current state pg_dump -U readur -d readur > emergency_backup_$(date +%Y%m%d_%H%M%S).sql # Try to repair psql -U readur -d readur < checksums.txt md5sum -c checksums.txt ``` ## Monitoring Commands ### System Health Monitoring ```bash # One-liner health check watch -n 5 'echo "=== System Health ===" && \ systemctl is-active readur postgresql nginx && \ echo "" && \ echo "=== Resources ===" && \ free -h | head -2 && \ echo "" && \ df -h | grep -E "/$|uploads" && \ echo "" && \ echo "=== Database ===" && \ psql -U readur -d readur -t -c "SELECT status, COUNT(*) FROM ocr_queue GROUP BY status;" && \ echo "" && \ echo "=== Recent Errors ===" && \ journalctl -u readur -n 5 --no-pager | grep -i error' ``` ## Getting Help ### Collect Diagnostic Information ```bash #!/bin/bash # collect-diagnostics.sh DIAG_DIR="readur-diagnostics-$(date +%Y%m%d_%H%M%S)" mkdir -p $DIAG_DIR # System information uname -a > $DIAG_DIR/system.txt free -h >> $DIAG_DIR/system.txt df -h >> $DIAG_DIR/system.txt # Service status systemctl status readur > $DIAG_DIR/readur-status.txt systemctl status postgresql > $DIAG_DIR/postgres-status.txt # Recent logs journalctl -u readur -n 1000 > $DIAG_DIR/readur-logs.txt tail -n 1000 /var/log/readur/app.log > $DIAG_DIR/app-logs.txt # Configuration (sanitized) env | grep -E "^READUR_|^DATABASE_|^OCR_" | sed 's/PASSWORD=.*/PASSWORD=***/' > $DIAG_DIR/config.txt # Database stats psql -U readur -d readur < $DIAG_DIR/db-stats.txt SELECT version(); SELECT COUNT(*) as documents FROM documents; SELECT COUNT(*) as users FROM users; SELECT status, COUNT(*) FROM ocr_queue GROUP BY status; EOF # Create archive tar -czf $DIAG_DIR.tar.gz $DIAG_DIR/ echo "Diagnostics collected in $DIAG_DIR.tar.gz" ``` ### Support Channels - **GitHub Issues**: https://github.com/readur/readur/issues - **Discord Community**: https://discord.gg/readur - **Documentation**: https://readur.app/docs - **Email Support**: support@readur.app (for enterprise customers) When reporting issues, include: 1. Diagnostic archive from above script 2. Steps to reproduce the issue 3. Expected vs actual behavior 4. Any error messages or screenshots 5. Your deployment environment details