File size: 6,788 Bytes
e35e5ca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# 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 |