143 lines
5.3 KiB
PowerShell
143 lines
5.3 KiB
PowerShell
|
# 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
|
||
|
}
|
||
|
}
|