# ScriptShare Management Script for Windows PowerShell param( [Parameter(Mandatory=$true, Position=0)] [string]$Command, [Parameter(Position=1)] [string]$Service ) $ComposeFile = "docker-compose.prod.yml" function Show-Help { Write-Host "ScriptShare Management Script" -ForegroundColor Green Write-Host "" Write-Host "Usage: .\scripts\manage.ps1 [COMMAND] [SERVICE]" -ForegroundColor Yellow Write-Host "" Write-Host "Commands:" -ForegroundColor Cyan Write-Host " start Start all services" Write-Host " stop Stop all services" Write-Host " restart Restart all services" Write-Host " logs Show logs for all services" Write-Host " logs [svc] Show logs for specific service" Write-Host " status Show status of all services" Write-Host " backup Create database backup" Write-Host " update Update application (pull, build, restart)" Write-Host " clean Clean up unused Docker resources" Write-Host " shell [svc] Open shell in service container" Write-Host " db Connect to database" Write-Host " help Show this help message" Write-Host "" Write-Host "Services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy, scriptshare-redis" -ForegroundColor Gray } switch ($Command.ToLower()) { "start" { Write-Host "๐Ÿš€ Starting ScriptShare services..." -ForegroundColor Green docker-compose -f $ComposeFile up -d Write-Host "โœ… Services started" -ForegroundColor Green } "stop" { Write-Host "๐Ÿ›‘ Stopping ScriptShare services..." -ForegroundColor Yellow docker-compose -f $ComposeFile down Write-Host "โœ… Services stopped" -ForegroundColor Green } "restart" { Write-Host "๐Ÿ”„ Restarting ScriptShare services..." -ForegroundColor Yellow docker-compose -f $ComposeFile restart Write-Host "โœ… Services restarted" -ForegroundColor Green } "logs" { if ($Service) { Write-Host "๐Ÿ“‹ Showing logs for $Service..." -ForegroundColor Cyan docker-compose -f $ComposeFile logs -f $Service } else { Write-Host "๐Ÿ“‹ Showing logs for all services..." -ForegroundColor Cyan docker-compose -f $ComposeFile logs -f } } "status" { Write-Host "๐Ÿ“Š Service Status:" -ForegroundColor Cyan docker-compose -f $ComposeFile ps Write-Host "" Write-Host "๐Ÿฅ Health Status:" -ForegroundColor Cyan $services = @("scriptshare-db", "scriptshare-api", "scriptshare-frontend", "scriptshare-proxy") foreach ($svc in $services) { try { $health = docker inspect --format='{{.State.Health.Status}}' $svc 2>$null if (-not $health) { $health = "not found" } Write-Host " $svc`: $health" -ForegroundColor Gray } catch { Write-Host " $svc`: not found" -ForegroundColor Red } } } "backup" { Write-Host "๐Ÿ—„๏ธ Creating database backup..." -ForegroundColor Cyan if (Test-Path ".\scripts\backup.sh") { bash .\scripts\backup.sh } else { Write-Host "โŒ Backup script not found. Please run manually:" -ForegroundColor Red Write-Host "docker exec scriptshare-db mysqladmin ping" -ForegroundColor Gray } } "update" { Write-Host "๐Ÿ”„ Updating ScriptShare application..." -ForegroundColor Cyan docker-compose -f $ComposeFile pull docker-compose -f $ComposeFile build --no-cache docker-compose -f $ComposeFile up -d Write-Host "โœ… Application updated" -ForegroundColor Green } "clean" { Write-Host "๐Ÿงน Cleaning up Docker resources..." -ForegroundColor Yellow docker system prune -f docker volume prune -f Write-Host "โœ… Cleanup completed" -ForegroundColor Green } "shell" { if (-not $Service) { Write-Host "โŒ Please specify service name" -ForegroundColor Red Write-Host "Available services: scriptshare-db, scriptshare-api, scriptshare-frontend, scriptshare-proxy" -ForegroundColor Gray exit 1 } Write-Host "๐Ÿ’ป Opening shell in $Service..." -ForegroundColor Cyan docker-compose -f $ComposeFile exec $Service /bin/sh } "db" { Write-Host "๐Ÿ—ƒ๏ธ Connecting to database..." -ForegroundColor Cyan $envFile = ".env" $dbUser = "scriptshare_user" $dbPassword = "ScriptShare_App_2024_Secure!" $dbName = "scriptshare" if (Test-Path $envFile) { $env = Get-Content $envFile | ConvertFrom-StringData if ($env.DB_USER) { $dbUser = $env.DB_USER } if ($env.DB_PASSWORD) { $dbPassword = $env.DB_PASSWORD } if ($env.DB_NAME) { $dbName = $env.DB_NAME } } docker-compose -f $ComposeFile exec scriptshare-db mysql -u $dbUser -p$dbPassword $dbName } "help" { Show-Help } default { Write-Host "โŒ Unknown command: $Command" -ForegroundColor Red Write-Host "" Show-Help exit 1 } }