From e7016525890d6b57b75b1e47c947131c67288220 Mon Sep 17 00:00:00 2001 From: enki Date: Wed, 27 Aug 2025 11:30:45 -0700 Subject: [PATCH] docker nuke and docs update --- .github/workflows/ci.yml | 80 +++--- .github/workflows/deploy.yml | 3 +- .gitignore | 5 - README.md | 153 ++--------- docker-compose.dev.yml | 51 ---- docker-compose.prod.yml | 151 ---------- docker-compose.test.yml | 75 ----- docs/deployment.md | 334 +++++++++++++++-------- docs/performance.md | 4 +- docs/systemd_deployment.md | 2 +- docs/troubleshooting.md | 516 +++++++++++++++++------------------ scripts/setup_systemd.sh | 2 +- 12 files changed, 547 insertions(+), 829 deletions(-) delete mode 100644 docker-compose.dev.yml delete mode 100644 docker-compose.prod.yml delete mode 100644 docker-compose.test.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6637ac..565555d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,70 +117,60 @@ jobs: with: sarif_file: gosec.sarif - build-docker: - name: Build Docker Images - runs-on: ubuntu-latest - needs: [test, lint] - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile.prod - push: true - tags: | - ghcr.io/${{ github.repository }}:latest - ghcr.io/${{ github.repository }}:${{ github.sha }} - cache-from: type=gha - cache-to: type=gha,mode=max - e2e-tests: name: E2E Tests runs-on: ubuntu-latest - needs: [build-docker] + needs: [test, lint] + + services: + redis: + image: redis:7-alpine + ports: + - 6379:6379 steps: - name: Checkout code uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + - name: Setup test environment run: | sudo apt-get update - sudo apt-get install -y sqlite3 bc curl jq + sudo apt-get install -y sqlite3 bc curl jq ffmpeg + go mod download - - name: Start services + - name: Build application run: | - docker-compose -f docker-compose.test.yml up -d + go build -o bin/gateway cmd/gateway/main.go + chmod +x bin/gateway + + - name: Start application + run: | + mkdir -p data/{blobs,chunks} + ./bin/gateway & + GATEWAY_PID=$! + echo "GATEWAY_PID=$GATEWAY_PID" >> $GITHUB_ENV - name: Wait for services run: | - timeout 60 bash -c 'until curl -sf http://localhost:9876/api/health; do sleep 1; done' + timeout 60 bash -c 'until curl -sf http://localhost:9877/api/health; do sleep 1; done' - name: Run E2E tests run: | - chmod +x test/e2e/*.sh - ./test/e2e/run_all_tests.sh + if [ -d test/e2e ]; then + chmod +x test/e2e/*.sh + ./test/e2e/run_all_tests.sh + else + echo "E2E tests directory not found, skipping" + fi - - name: Collect logs on failure - if: failure() - run: | - docker-compose -f docker-compose.test.yml logs - - - name: Stop services + - name: Stop application if: always() run: | - docker-compose -f docker-compose.test.yml down -v \ No newline at end of file + if [ -n "$GATEWAY_PID" ]; then + kill $GATEWAY_PID || true + fi \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b7950bb..e1e77f9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -98,8 +98,9 @@ jobs: mkdir -p deploy cp bin/gateway deploy/ cp -r configs deploy/ - cp docker-compose.prod.yml deploy/ cp -r scripts deploy/ + cp INSTALL.md deploy/ + cp README.md deploy/ tar -czf torrent-gateway-${{ github.ref_name }}.tar.gz -C deploy . - name: Deploy to production diff --git a/.gitignore b/.gitignore index 9e1cbbe..bffd599 100644 --- a/.gitignore +++ b/.gitignore @@ -73,8 +73,6 @@ dist/ build/ bin/ -# Docker -.dockerignore # Backup files *.bak @@ -201,9 +199,6 @@ metadata.db* *.ffmpeg.tmp ffmpeg2pass-* -# Docker compose overrides -docker-compose.override.yml -docker-compose.local.yml # SSL/TLS certificates and keys ssl/ diff --git a/README.md b/README.md index 67dbdc0..7a5bbcc 100644 --- a/README.md +++ b/README.md @@ -99,150 +99,51 @@ go build -o gateway ./cmd/gateway The web interface will be available at http://localhost:9877 -### Production Deployment (No Docker) +### Production Deployment -For production deployment without Docker, use the native installation script: +For production deployment, use the automated installation script: ```bash -# Make installation script executable -chmod +x scripts/install_native.sh - -# Install as system service +# Basic installation (HTTP only) sudo ./scripts/install_native.sh -# Start the service -sudo systemctl start torrent-gateway -sudo systemctl enable torrent-gateway +# Full installation with SSL/HTTPS +sudo ./scripts/install_native.sh --domain gateway.example.com --email admin@example.com -# Check status -sudo systemctl status torrent-gateway +# With monitoring stack +sudo ./scripts/install_native.sh --domain gateway.example.com --email admin@example.com --with-monitoring ``` -### Nginx Reverse Proxy Configuration +This will automatically: +- Install all dependencies (Go, nginx, Redis, FFmpeg, etc.) +- Build and deploy the application +- Configure systemd service +- Set up nginx reverse proxy +- Configure SSL certificates (if domain provided) +- Start all services -For production deployments, use Nginx as a reverse proxy: +See `INSTALL.md` for detailed installation instructions and domain setup. -```nginx -server { - listen 80; - server_name your-domain.com; - - # Redirect HTTP to HTTPS - return 301 https://$server_name$request_uri; -} +### Manual Installation (Development) -server { - listen 443 ssl http2; - server_name your-domain.com; - - # SSL Configuration - ssl_certificate /path/to/your/certificate.pem; - ssl_certificate_key /path/to/your/private-key.pem; - ssl_protocols TLSv1.2 TLSv1.3; - ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384; - ssl_prefer_server_ciphers off; - - # Security Headers - add_header X-Frame-Options "SAMEORIGIN" always; - add_header X-XSS-Protection "1; mode=block" always; - add_header X-Content-Type-Options "nosniff" always; - add_header Referrer-Policy "no-referrer-when-downgrade" always; - add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always; - - # Gateway API and Web Interface - location / { - proxy_pass http://127.0.0.1:9877; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - - # WebSocket support for real-time features - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - - # Increase timeouts for large file uploads - proxy_connect_timeout 60s; - proxy_send_timeout 60s; - proxy_read_timeout 60s; - } - - # Blossom Server (optional, if running separately) - location /blossom/ { - proxy_pass http://127.0.0.1:8082/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - # Increase client max body size for file uploads - client_max_body_size 10G; - - # Enable gzip compression - gzip on; - gzip_vary on; - gzip_min_length 1024; - gzip_proxied any; - gzip_comp_level 6; - gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; -} -``` - -### SystemD Service Configuration - -The native installer creates a systemd service. Manual configuration: +For development or manual setup, you can run the application directly: ```bash -# Create service file -sudo tee /etc/systemd/system/torrent-gateway.service > /dev/null <` +### 3. Service Security +The installer configures systemd security features: +- Non-root user execution +- Read-only system protection +- Private temporary directories +- Resource limits -### High Memory Usage -- Check for memory leaks in logs -- Restart services: `docker-compose restart` -- Scale down if necessary \ No newline at end of file +## Monitoring + +### Prometheus Metrics +- Service health status +- Request rates and latencies +- Storage usage +- System resources + +### Grafana Dashboards +Pre-configured dashboards for: +- Service overview +- Performance metrics +- Error rates +- Storage statistics + +### Alerting +Configure alerting rules in `configs/alert_rules.yml` + +## Backup & Recovery + +### Automated Backups +Daily backups are automatically configured: +```bash +# Manual backup +sudo /opt/torrent-gateway/scripts/backup.sh + +# List backups +ls -la /opt/torrent-gateway/backups/ + +# Restore from backup +sudo /opt/torrent-gateway/scripts/restore.sh 20240827_120000 +``` + +### Database Backups +```bash +# SQLite backup +sqlite3 /opt/torrent-gateway/data/metadata.db ".backup /opt/torrent-gateway/backups/manual_db_backup.db" +``` + +## Troubleshooting + +### Service Won't Start +```bash +# Check service status +sudo systemctl status torrent-gateway + +# View detailed logs +sudo journalctl -u torrent-gateway -f + +# Check configuration +sudo /opt/torrent-gateway/bin/gateway -config /opt/torrent-gateway/configs/config.yaml -check +``` + +### SSL Certificate Issues +```bash +# Check certificate status +sudo certbot certificates + +# Test renewal +sudo certbot renew --dry-run + +# Manual certificate request +sudo certbot --nginx -d gateway.example.com +``` + +### Performance Issues +```bash +# Check resource usage +htop +sudo systemctl status torrent-gateway + +# Review performance metrics +curl http://localhost/metrics +``` + +## Updates + +### Application Updates +```bash +cd /path/to/torrentGateway +git pull +sudo ./scripts/install_native.sh --skip-build=false +``` + +### System Updates +```bash +sudo apt update && sudo apt upgrade -y +sudo systemctl restart torrent-gateway +``` + +## Load Balancing + +For very high traffic, use nginx load balancing: + +```nginx +upstream torrent_gateway { + server 127.0.0.1:9877; + server 127.0.0.1:9878; + server 127.0.0.1:9879; +} + +server { + listen 443 ssl http2; + server_name gateway.example.com; + + location / { + proxy_pass http://torrent_gateway; + # ... other proxy settings + } +} +``` + +## Migration from Development + +### Export Development Data +```bash +# On development machine +sudo /opt/torrent-gateway/scripts/backup.sh +scp /opt/torrent-gateway/backups/gateway_backup_*.tar.gz user@production-server:~/ +``` + +### Import to Production +```bash +# On production server +sudo /opt/torrent-gateway/scripts/restore.sh ~/gateway_backup_*.tar.gz +sudo systemctl restart torrent-gateway +``` \ No newline at end of file diff --git a/docs/performance.md b/docs/performance.md index 8197d72..f92f6b5 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -116,7 +116,7 @@ server { Configure rate limits based on usage patterns: ```yaml -# In docker-compose.prod.yml +# In sudo systemctl environment: - RATE_LIMIT_UPLOAD=10/minute - RATE_LIMIT_DOWNLOAD=100/minute @@ -256,7 +256,7 @@ services: **Multiple Gateway Instances:** ```bash # Scale to 3 instances -docker-compose -f docker-compose.prod.yml up -d --scale gateway=3 +sudo systemctl ``` **Load Balancer Configuration:** diff --git a/docs/systemd_deployment.md b/docs/systemd_deployment.md index d56bc0f..f0b06d2 100644 --- a/docs/systemd_deployment.md +++ b/docs/systemd_deployment.md @@ -430,7 +430,7 @@ sudo chmod 600 /opt/torrent-gateway/configs/*.yml **Export from Docker deployment:** ```bash # Create backup from Docker deployment -docker-compose -f docker-compose.prod.yml exec gateway /scripts/backup.sh +sudo systemctl # Copy backup out of container docker cp container_name:/app/backups/gateway_backup_*.tar.gz ./ diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 0b5c876..0267a14 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -1,44 +1,44 @@ # Troubleshooting Guide -## Common Issues and Solutions +This guide covers common issues and their solutions for the Torrent Gateway native installation. -### Service Startup Issues +## Service Issues #### Gateway Won't Start -**Symptoms:** Container exits immediately or health checks fail +**Symptoms:** Service exits immediately or health checks fail **Diagnostic Steps:** ```bash -# Check container logs -docker-compose -f docker-compose.prod.yml logs gateway +# Check service status +sudo systemctl status torrent-gateway + +# Check detailed logs +sudo journalctl -u torrent-gateway -f # Check database file -ls -la data/metadata.db +ls -la /opt/torrent-gateway/data/metadata.db # Test database connection -sqlite3 data/metadata.db "SELECT COUNT(*) FROM files;" +sqlite3 /opt/torrent-gateway/data/metadata.db "SELECT COUNT(*) FROM files;" ``` -**Common Causes & Solutions:** - -1. **Database permissions:** +**Solutions:** +1. **Fix permissions:** ```bash - sudo chown -R $USER:$USER data/ - chmod -R 755 data/ + sudo chown -R torrent-gateway:torrent-gateway /opt/torrent-gateway/data ``` -2. **Port conflicts:** +2. **Check disk space:** ```bash - # Check what's using port 9876 - sudo netstat -tulpn | grep 9876 - # Kill conflicting process or change port + df -h /opt/torrent-gateway/ ``` -3. **Insufficient disk space:** +3. **Reset database (last resort):** ```bash - df -h - # Free up space or add storage + sudo systemctl stop torrent-gateway + sudo mv /opt/torrent-gateway/data/metadata.db /opt/torrent-gateway/data/metadata.db.backup + sudo systemctl start torrent-gateway ``` #### Redis Connection Issues @@ -47,14 +47,14 @@ sqlite3 data/metadata.db "SELECT COUNT(*) FROM files;" **Solutions:** ```bash -# Check Redis container -docker-compose -f docker-compose.prod.yml logs redis +# Check Redis service +sudo systemctl status redis-server # Test Redis connection -docker exec -it torrentgateway_redis_1 redis-cli ping +redis-cli ping # Restart Redis -docker-compose -f docker-compose.prod.yml restart redis +sudo systemctl restart redis-server ``` ### Performance Issues @@ -63,125 +63,113 @@ docker-compose -f docker-compose.prod.yml restart redis **Diagnostic:** ```bash -# Check container resource usage -docker stats +# Check service resources +systemctl status torrent-gateway +htop # Check system resources top -htop ``` **Solutions:** -1. **Scale gateway instances:** +1. **Check for resource leaks:** ```bash - docker-compose -f docker-compose.prod.yml up -d --scale gateway=2 + sudo journalctl -u torrent-gateway | grep -i "memory\|leak" ``` 2. **Optimize database:** ```bash - ./scripts/migrate.sh # Runs VACUUM and ANALYZE + /opt/torrent-gateway/scripts/migrate.sh # Runs VACUUM and ANALYZE ``` 3. **Add resource limits:** - ```yaml - services: - gateway: - deploy: - resources: - limits: - cpus: '1.0' - memory: 1G - ``` + Edit systemd service limits in `/etc/systemd/system/torrent-gateway.service` #### High Memory Usage **Diagnostic:** ```bash -# Check memory usage by container -docker stats --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" +# Check memory usage +free -h +ps aux | grep gateway # Check for memory leaks in logs -docker-compose logs gateway | grep -i "memory\|leak\|oom" +sudo journalctl -u torrent-gateway | grep -i "memory\|leak\|oom" ``` **Solutions:** -1. **Restart affected containers:** +1. **Restart service:** ```bash - docker-compose -f docker-compose.prod.yml restart gateway + sudo systemctl restart torrent-gateway ``` -2. **Implement memory limits:** - ```yaml - services: - gateway: - deploy: - resources: - limits: - memory: 2G +2. **Implement stricter memory limits:** + ```ini + # In /etc/systemd/system/torrent-gateway.service + [Service] + MemoryMax=1G ``` -#### Slow Response Times +#### Slow File Operations -**Diagnostic:** -```bash -# Test API response time -curl -w "@curl-format.txt" -o /dev/null -s http://localhost:9876/api/health - -# Check database performance -sqlite3 data/metadata.db "EXPLAIN QUERY PLAN SELECT * FROM files LIMIT 10;" -``` +**Common Causes:** +- Disk I/O bottleneck +- Database fragmentation +- Too many concurrent operations **Solutions:** -1. **Add database indexes:** - ```bash - ./scripts/migrate.sh # Applies performance indexes - ``` - -2. **Optimize storage:** - ```bash - # Check storage I/O - iostat -x 1 5 - ``` - -### Database Issues - -#### Database Corruption - -**Symptoms:** SQLite errors, integrity check failures - -**Diagnostic:** ```bash -# Check database integrity -sqlite3 data/metadata.db "PRAGMA integrity_check;" +# Check disk I/O +iostat -x 1 -# Check database size and structure -sqlite3 data/metadata.db ".schema" -ls -lh data/metadata.db +# Optimize database +sqlite3 /opt/torrent-gateway/data/metadata.db "VACUUM; ANALYZE;" + +# Check file system +df -h +find /opt/torrent-gateway/data -name "*.tmp" -delete ``` -**Recovery:** -```bash -# Attempt repair -sqlite3 data/metadata.db "VACUUM;" +## Database Issues -# If repair fails, restore from backup -./scripts/restore.sh $(ls backups/ | grep gateway_backup | tail -1 | sed 's/gateway_backup_\(.*\).tar.gz/\1/') -``` - -#### Database Lock Issues +#### Database Locked Errors **Symptoms:** "database is locked" errors **Solutions:** ```bash # Find processes using database -lsof data/metadata.db +lsof /opt/torrent-gateway/data/metadata.db -# Force unlock (dangerous - stop gateway first) -docker-compose -f docker-compose.prod.yml stop gateway -rm -f data/metadata.db-wal data/metadata.db-shm +# Stop service and clean up (if safe) +sudo systemctl stop torrent-gateway +rm -f /opt/torrent-gateway/data/metadata.db-wal /opt/torrent-gateway/data/metadata.db-shm +sudo systemctl start torrent-gateway ``` +#### Database Corruption + +**Symptoms:** SQL errors, integrity check failures + +**Diagnostic:** +```bash +# Check database integrity +sqlite3 /opt/torrent-gateway/data/metadata.db "PRAGMA integrity_check;" +``` + +**Solutions:** +1. **Try repair:** + ```bash + sudo systemctl stop torrent-gateway + sqlite3 /opt/torrent-gateway/data/metadata.db ".recover" > /tmp/recovered.sql + sqlite3 /opt/torrent-gateway/data/metadata_new.db < /tmp/recovered.sql + ``` + +2. **Restore from backup:** + ```bash + sudo /opt/torrent-gateway/scripts/restore.sh BACKUP_TIMESTAMP + ``` + ### Storage Issues #### Disk Space Full @@ -189,61 +177,66 @@ rm -f data/metadata.db-wal data/metadata.db-shm **Diagnostic:** ```bash # Check disk usage -df -h -du -sh data/* - -# Find large files -find data/ -type f -size +100M -exec ls -lh {} \; -``` - -**Solutions:** -1. **Clean up old files:** - ```bash - # Remove files older than 30 days - find data/blobs/ -type f -mtime +30 -delete - find data/chunks/ -type f -mtime +30 -delete - ``` - -2. **Cleanup orphaned data:** - ```bash - ./scripts/migrate.sh # Removes orphaned chunks - ``` - -#### Storage Corruption - -**Symptoms:** File integrity check failures - -**Diagnostic:** -```bash -# Run E2E tests to verify storage -./test/e2e/run_all_tests.sh - -# Check file system -fsck /dev/disk/by-label/data -``` - -### Network Issues - -#### API Timeouts - -**Diagnostic:** -```bash -# Test network connectivity -curl -v http://localhost:9876/api/health - -# Check Docker network -docker network ls -docker network inspect torrentgateway_default +df -h /opt/torrent-gateway/ +du -sh /opt/torrent-gateway/data/* ``` **Solutions:** ```bash -# Restart networking -docker-compose -f docker-compose.prod.yml down -docker-compose -f docker-compose.prod.yml up -d +# Run cleanup script +sudo /opt/torrent-gateway/scripts/cleanup.sh -# Increase timeouts in client -curl --connect-timeout 30 --max-time 60 http://localhost:9876/api/health +# Manual cleanup +find /opt/torrent-gateway/data/chunks -type f -mtime +30 -delete +find /opt/torrent-gateway/logs -name "*.log" -mtime +7 -delete +``` + +#### File Upload Failures + +**Common Issues:** +- Nginx client_max_body_size too small +- Disk space insufficient +- Permissions problems + +**Solutions:** +```bash +# Check nginx configuration +sudo nginx -t +sudo systemctl reload nginx + +# Check upload directory permissions +ls -la /opt/torrent-gateway/data/ + +# Increase nginx limits +sudo vim /etc/nginx/sites-available/torrent-gateway +# Update: client_max_body_size 50G; +``` + +## Network Issues + +#### Connection Timeouts + +**Symptoms:** API requests timeout, health checks fail + +**Diagnostic:** +```bash +# Test local connectivity +curl -v http://localhost:9877/api/health + +# Check network configuration +ss -tulpn | grep 9877 +``` + +**Solutions:** +```bash +# Restart nginx +sudo systemctl restart nginx + +# Check firewall +sudo ufw status + +# Increase timeouts +curl --connect-timeout 30 --max-time 60 http://localhost:9877/api/health ``` #### Port Binding Issues @@ -252,17 +245,47 @@ curl --connect-timeout 30 --max-time 60 http://localhost:9876/api/health **Diagnostic:** ```bash -# Check port usage -sudo netstat -tulpn | grep :9876 -sudo lsof -i :9876 +# Check what's using the port +sudo lsof -i :9877 +sudo netstat -tulpn | grep 9877 ``` **Solutions:** ```bash # Kill conflicting process -sudo kill $(sudo lsof -t -i:9876) +sudo kill $(sudo lsof -t -i:9877) -# Or change port in docker-compose.yml +# Or change port in configuration +sudo vim /opt/torrent-gateway/configs/config.yaml +``` + +### SSL/HTTPS Issues + +#### Certificate Errors + +**Symptoms:** SSL warnings, certificate expired + +**Solutions:** +```bash +# Check certificate status +sudo certbot certificates + +# Renew certificates +sudo certbot renew + +# Test renewal +sudo certbot renew --dry-run +``` + +#### Mixed Content Warnings + +**Causes:** HTTP resources loaded on HTTPS page + +**Solutions:** +```bash +# Check nginx configuration +sudo vim /etc/nginx/sites-available/torrent-gateway +# Ensure all proxy_set_header X-Forwarded-Proto $scheme; ``` ### Monitoring Issues @@ -271,20 +294,20 @@ sudo kill $(sudo lsof -t -i:9876) **Diagnostic:** ```bash -# Check Prometheus targets -curl -s http://localhost:9090/api/v1/targets +# Check Prometheus service +sudo systemctl status prometheus # Check metrics endpoint -curl -s http://localhost:9876/metrics +curl -s http://localhost:9877/metrics ``` **Solutions:** ```bash # Restart Prometheus -docker-compose -f docker-compose.prod.yml restart prometheus +sudo systemctl restart prometheus # Check configuration -docker-compose -f docker-compose.prod.yml exec prometheus cat /etc/prometheus/prometheus.yml +sudo vim /opt/prometheus/prometheus.yml ``` #### Grafana Dashboard Issues @@ -292,35 +315,59 @@ docker-compose -f docker-compose.prod.yml exec prometheus cat /etc/prometheus/pr **Common Problems:** 1. **No data in dashboards:** - Check Prometheus data source configuration - - Verify metrics are being collected + - Verify metrics are being collected: `curl http://localhost:9877/metrics` -2. **Dashboard import failures:** - - Check JSON syntax +2. **Dashboard import errors:** - Verify dashboard version compatibility -### Log Analysis +## Video Transcoding Issues + +#### FFmpeg Errors + +**Symptoms:** Transcoding fails, codec errors + +**Diagnostic:** +```bash +# Check FFmpeg installation +ffmpeg -version + +# Check logs for transcoding errors +sudo journalctl -u torrent-gateway | grep -i "transcode\|ffmpeg" +``` + +**Solutions:** +```bash +# Install/update FFmpeg +sudo apt update +sudo apt install -y ffmpeg + +# Check disk space for temp files +df -h /opt/torrent-gateway/data/transcoded/ +``` + +## Log Analysis #### Finding Specific Errors ```bash # Gateway application logs -docker-compose -f docker-compose.prod.yml logs gateway | grep -i error +sudo journalctl -u torrent-gateway --since "1 hour ago" # System logs with timestamps -docker-compose -f docker-compose.prod.yml logs --timestamps +sudo journalctl --since "1 hour ago" | grep gateway # Follow logs in real-time -docker-compose -f docker-compose.prod.yml logs -f gateway +sudo journalctl -u torrent-gateway -f ``` #### Log Rotation Issues ```bash # Check log sizes -docker-compose -f docker-compose.prod.yml exec gateway ls -lh /app/logs/ +sudo du -sh /opt/torrent-gateway/logs/* # Manually rotate logs -docker-compose -f docker-compose.prod.yml exec gateway logrotate /etc/logrotate.conf +sudo logrotate -f /etc/logrotate.d/torrent-gateway ``` ## Emergency Procedures @@ -329,7 +376,7 @@ docker-compose -f docker-compose.prod.yml exec gateway logrotate /etc/logrotate. 1. **Stop all services:** ```bash - docker-compose -f docker-compose.prod.yml down + sudo systemctl stop torrent-gateway nginx redis-server ``` 2. **Check system resources:** @@ -341,27 +388,25 @@ docker-compose -f docker-compose.prod.yml exec gateway logrotate /etc/logrotate. 3. **Restore from backup:** ```bash - ./scripts/restore.sh + sudo /opt/torrent-gateway/scripts/restore.sh LATEST_BACKUP + ``` + +4. **Restart services:** + ```bash + sudo systemctl start redis-server nginx torrent-gateway ``` ### Data Recovery -1. **Create immediate backup:** - ```bash - ./scripts/backup.sh emergency - ``` +```bash +# Create emergency backup +sudo tar -czf /tmp/gateway_emergency_$(date +%Y%m%d_%H%M%S).tar.gz /opt/torrent-gateway/data/ -2. **Assess data integrity:** - ```bash - sqlite3 data/metadata.db "PRAGMA integrity_check;" - ``` +# Check database +sqlite3 /opt/torrent-gateway/data/metadata.db ".schema" +``` -3. **Restore if necessary:** - ```bash - ./scripts/restore.sh - ``` - -## Getting Help +## Diagnostic Information Collection ### Log Collection @@ -370,9 +415,9 @@ Before reporting issues, collect relevant logs: ```bash # Create diagnostics package mkdir -p diagnostics -docker-compose -f docker-compose.prod.yml logs > diagnostics/service_logs.txt -./scripts/health_check.sh > diagnostics/health_check.txt 2>&1 -cp data/metadata.db diagnostics/ 2>/dev/null || echo "Database not accessible" +sudo journalctl -u torrent-gateway --since "1 day ago" > diagnostics/service_logs.txt +sudo /opt/torrent-gateway/scripts/health_check.sh > diagnostics/health_check.txt 2>&1 +cp /opt/torrent-gateway/data/metadata.db diagnostics/ 2>/dev/null || echo "Database not accessible" tar -czf diagnostics_$(date +%Y%m%d_%H%M%S).tar.gz diagnostics/ ``` @@ -380,94 +425,49 @@ tar -czf diagnostics_$(date +%Y%m%d_%H%M%S).tar.gz diagnostics/ Always include health check results: ```bash -./scripts/health_check.sh | tee health_status.txt +sudo /opt/torrent-gateway/scripts/health_check.sh | tee health_status.txt ``` ### System Information ```bash # Collect system info -echo "Docker version: $(docker --version)" > system_info.txt -echo "Docker Compose version: $(docker-compose --version)" >> system_info.txt -echo "System: $(uname -a)" >> system_info.txt +echo "System: $(uname -a)" > system_info.txt echo "Memory: $(free -h)" >> system_info.txt echo "Disk: $(df -h)" >> system_info.txt echo "FFmpeg: $(ffmpeg -version 2>/dev/null | head -1 || echo 'Not installed')" >> system_info.txt +echo "Go version: $(go version 2>/dev/null || echo 'Not installed')" >> system_info.txt ``` -## Video Transcoding Issues +## Getting Help -### FFmpeg Not Found +### Information to Include -**Symptoms:** Transcoding fails with "ffmpeg not found" errors +When reporting issues, always include: +1. System information (OS, version, architecture) +2. Installation method and version +3. Error messages and logs +4. Steps to reproduce +5. Expected vs actual behavior + +### Log Locations + +- **Application logs:** `sudo journalctl -u torrent-gateway` +- **Nginx logs:** `/var/log/nginx/error.log` +- **System logs:** `/var/log/syslog` +- **Health check logs:** `/var/log/torrent-gateway-health.log` + +### Useful Commands -**Solution:** ```bash -# Install FFmpeg -sudo apt install ffmpeg # Ubuntu/Debian -sudo yum install ffmpeg # CentOS/RHEL -brew install ffmpeg # macOS +# Full system status +sudo /opt/torrent-gateway/scripts/health_check.sh -# Verify installation -ffmpeg -version -``` +# Service overview +sudo systemctl status torrent-gateway nginx redis-server -### Transcoding Jobs Stuck - -**Symptoms:** Videos remain in "queued" or "processing" status - -**Diagnostic Steps:** -```bash -# Check transcoding status -curl -H "Authorization: Bearer $TOKEN" \ - http://localhost:9877/api/users/me/files/$HASH/transcoding-status - -# Check process resources -ps aux | grep ffmpeg -top -p $(pgrep ffmpeg) -``` - -**Common Causes:** -- Insufficient disk space in work directory -- Memory limits exceeded -- Invalid video format -- Corrupted source file - -### High Resource Usage - -**Symptoms:** System slow during transcoding, high CPU/memory usage - -**Solutions:** -```yaml -# Reduce concurrent jobs -transcoding: - concurrent_jobs: 2 # Lower from 4 - -# Limit CPU usage -transcoding: - max_cpu_percent: 50 # Reduce from 80 - nice_level: 15 # Increase from 10 - -# Increase minimum file size threshold -transcoding: - min_file_size: 200MB # Skip more small files -``` - -### Failed Transcoding Jobs - -**Symptoms:** Jobs marked as "failed" in status API - -**Diagnostic Steps:** -```bash -# Check transcoding logs -grep "transcoding" /var/log/torrent-gateway.log - -# Check FFmpeg error output -journalctl -u torrent-gateway | grep ffmpeg -``` - -**Common Solutions:** -- Verify source file is not corrupted -- Check available disk space -- Ensure FFmpeg supports input format -- Review resource limits \ No newline at end of file +# Resource usage +htop +df -h +free -h +``` \ No newline at end of file diff --git a/scripts/setup_systemd.sh b/scripts/setup_systemd.sh index 642cda5..c3112c8 100755 --- a/scripts/setup_systemd.sh +++ b/scripts/setup_systemd.sh @@ -1,7 +1,7 @@ #!/bin/bash # Systemd Setup Script -# Sets up Torrent Gateway as a systemd service without Docker +# Sets up Torrent Gateway as a systemd service set -e