| # BackgroundFX Pro Scripts |
|
|
| Utility scripts for setup, deployment, maintenance, and monitoring of BackgroundFX Pro. |
|
|
| ## Available Scripts |
|
|
| ### setup.sh |
| Complete environment setup script that handles: |
| - System requirements checking |
| - Virtual environment creation |
| - Dependency installation |
| - Model downloading |
| - Configuration creation |
| - CLI installation |
|
|
| **Usage:** |
| ```bash |
| chmod +x scripts/setup.sh |
| ./scripts/setup.sh |
| ``` |
|
|
| ### deploy.sh |
| Deployment automation script supporting multiple environments and methods: |
| - Docker deployment |
| - Kubernetes deployment |
| - Server deployment |
| - Health checks and rollback |
|
|
| **Usage:** |
| ```bash |
| # Deploy to production with Docker |
| ./scripts/deploy.sh --env production --method docker |
| |
| # Deploy to staging with specific version |
| ./scripts/deploy.sh --env staging --version 1.2.0 --registry myregistry.com |
| |
| # Deploy to Kubernetes |
| ./scripts/deploy.sh --env production --method kubernetes |
| |
| # Deploy to server (requires DEPLOY_HOST and DEPLOY_USER env vars) |
| export DEPLOY_HOST=server.example.com |
| export DEPLOY_USER=deploy |
| ./scripts/deploy.sh --method server |
| ``` |
|
|
| ### benchmark.py |
| Performance benchmarking script for testing various aspects: |
| - Image processing speed |
| - Model loading times |
| - Video processing performance |
| - Batch processing throughput |
|
|
| **Usage:** |
| ```bash |
| # Run all benchmarks |
| python scripts/benchmark.py |
| |
| # Run specific benchmarks |
| python scripts/benchmark.py --tests image model |
| |
| # Save results to specific file |
| python scripts/benchmark.py --output results.json --iterations 10 |
| ``` |
|
|
| ### monitor.py |
| System monitoring script for production environments: |
| - Resource usage tracking |
| - Processing statistics |
| - Error monitoring |
| - Performance metrics |
|
|
| **Usage:** |
| ```bash |
| # Start monitoring |
| python scripts/monitor.py |
| |
| # Monitor with custom interval |
| python scripts/monitor.py --interval 30 |
| |
| # Export metrics to Prometheus |
| python scripts/monitor.py --export prometheus |
| ``` |
|
|
| ### backup.sh |
| Backup and restore script for data and configurations: |
| - Model backups |
| - Configuration backups |
| - Database backups |
| - Volume backups (Docker) |
|
|
| **Usage:** |
| ```bash |
| # Create backup |
| ./scripts/backup.sh create |
| |
| # Restore from backup |
| ./scripts/backup.sh restore --file backup_20240101_120000.tar.gz |
| |
| # Schedule automatic backups |
| ./scripts/backup.sh schedule --cron "0 2 * * *" |
| ``` |
|
|
| ### update.sh |
| Update script for upgrading BackgroundFX Pro: |
| - Git pull latest changes |
| - Update dependencies |
| - Download new models |
| - Database migrations |
| - Rolling restart |
|
|
| **Usage:** |
| ```bash |
| # Update to latest version |
| ./scripts/update.sh |
| |
| # Update to specific version |
| ./scripts/update.sh --version 2.0.0 |
| |
| # Update without restart |
| ./scripts/update.sh --no-restart |
| ``` |
|
|
| ### clean.sh |
| Cleanup script for maintenance: |
| - Remove temporary files |
| - Clear cache |
| - Clean old logs |
| - Remove unused Docker images |
| - Free disk space |
|
|
| **Usage:** |
| ```bash |
| # Basic cleanup |
| ./scripts/clean.sh |
| |
| # Aggressive cleanup |
| ./scripts/clean.sh --aggressive |
| |
| # Dry run (show what would be deleted) |
| ./scripts/clean.sh --dry-run |
| ``` |
|
|
| ## Environment Variables |
|
|
| Many scripts use environment variables for configuration: |
|
|
| ```bash |
| # Deployment |
| export DEPLOY_HOST=server.example.com |
| export DEPLOY_USER=deploy |
| export DEPLOY_KEY=/path/to/key.pem |
| |
| # Docker Registry |
| export REGISTRY=myregistry.com |
| export REGISTRY_USER=username |
| export REGISTRY_PASS=password |
| |
| # Backup |
| export BACKUP_DIR=/backups |
| export S3_BUCKET=my-backups |
| export AWS_ACCESS_KEY_ID=xxx |
| export AWS_SECRET_ACCESS_KEY=xxx |
| |
| # Monitoring |
| export PROMETHEUS_PUSHGATEWAY=http://prometheus:9091 |
| export SLACK_WEBHOOK=https://hooks.slack.com/xxx |
| ``` |
|
|
| ## Cron Jobs |
|
|
| Example crontab entries for automated tasks: |
|
|
| ```cron |
| # Daily backup at 2 AM |
| 0 2 * * * /opt/backgroundfx/scripts/backup.sh create |
| |
| # Hourly monitoring export |
| 0 * * * * /opt/backgroundfx/scripts/monitor.py --export prometheus |
| |
| # Weekly cleanup on Sunday at 3 AM |
| 0 3 * * 0 /opt/backgroundfx/scripts/clean.sh |
| |
| # Daily model updates at 4 AM |
| 0 4 * * * /opt/backgroundfx/scripts/update_models.py |
| ``` |
|
|
| ## Docker Integration |
|
|
| Running scripts in Docker containers: |
|
|
| ```bash |
| # Run setup in container |
| docker run --rm -v $(pwd):/app backgroundfx-pro:latest ./scripts/setup.sh |
| |
| # Run benchmark |
| docker run --rm --gpus all backgroundfx-pro:latest python scripts/benchmark.py |
| |
| # Backup Docker volumes |
| docker run --rm \ |
| -v backgroundfx_data:/data \ |
| -v $(pwd)/backups:/backups \ |
| backgroundfx-pro:latest ./scripts/backup.sh create |
| ``` |
|
|
| ## CI/CD Integration |
|
|
| ### GitHub Actions |
|
|
| ```yaml |
| name: Deploy |
| on: |
| push: |
| branches: [main] |
| |
| jobs: |
| deploy: |
| runs-on: ubuntu-latest |
| steps: |
| - uses: actions/checkout@v2 |
| - name: Deploy to production |
| env: |
| DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} |
| DEPLOY_USER: ${{ secrets.DEPLOY_USER }} |
| run: | |
| ./scripts/deploy.sh --env production --method server |
| ``` |
|
|
| ### GitLab CI |
|
|
| ```yaml |
| deploy: |
| stage: deploy |
| script: |
| - ./scripts/deploy.sh --env production --method kubernetes |
| only: |
| - main |
| ``` |
|
|
| ## Troubleshooting |
|
|
| ### Permission Issues |
| ```bash |
| # Make scripts executable |
| chmod +x scripts/*.sh |
| |
| # Fix ownership |
| sudo chown -R $USER:$USER scripts/ |
| ``` |
|
|
| ### Path Issues |
| ```bash |
| # Add scripts to PATH |
| export PATH=$PATH:/opt/backgroundfx/scripts |
| |
| # Or create symlinks |
| sudo ln -s /opt/backgroundfx/scripts/bgfx-deploy /usr/local/bin/ |
| ``` |
|
|
| ### Python Scripts Not Found |
| ```bash |
| # Ensure virtual environment is activated |
| source venv/bin/activate |
| |
| # Or use full Python path |
| /opt/backgroundfx/venv/bin/python scripts/benchmark.py |
| ``` |
|
|
| ## Development |
|
|
| ### Adding New Scripts |
|
|
| 1. Create script in `scripts/` directory |
| 2. Add shebang line (`#!/bin/bash` or `#!/usr/bin/env python3`) |
| 3. Make executable: `chmod +x scripts/your_script.sh` |
| 4. Add documentation to this README |
| 5. Test in Docker environment |
|
|
| ### Script Template |
|
|
| ```bash |
| #!/bin/bash |
| # Script description |
| # Usage: script.sh [options] |
| |
| set -e # Exit on error |
| |
| # Configuration |
| SCRIPT_DIR=$(dirname $(realpath $0)) |
| PROJECT_ROOT=$(dirname $SCRIPT_DIR) |
| |
| # Colors |
| RED='\033[0;31m' |
| GREEN='\033[0;32m' |
| NC='\033[0m' |
| |
| # Functions |
| show_help() { |
| cat << EOF |
| Usage: $0 [OPTIONS] |
| Description of what the script does |
| |
| Options: |
| --help Show this help message |
| EOF |
| } |
| |
| # Main logic |
| main() { |
| echo "Running script..." |
| # Your code here |
| } |
| |
| # Parse arguments |
| while [[ $# -gt 0 ]]; do |
| case $1 in |
| --help) |
| show_help |
| exit 0 |
| ;; |
| *) |
| echo "Unknown option: $1" |
| show_help |
| exit 1 |
| ;; |
| esac |
| done |
| |
| # Run main function |
| main |
| ``` |
|
|
| ## Security Considerations |
|
|
| - Never commit sensitive data in scripts |
| - Use environment variables for secrets |
| - Validate all user inputs |
| - Use `set -e` to exit on errors |
| - Implement proper error handling |
| - Log actions for audit trail |
| - Restrict script permissions appropriately |