schon/scripts/Windows/restart.ps1
Egor fureunoir Gorbunov 7efc19e081 feat(monitoring): automate Prometheus web config generation
Remove manual password hashing and web.yml setup in favor of automated generation. Add scripts for both Unix and Windows to create `monitoring/web.yml` using credentials from `.env`.

This improves maintainability and reduces manual intervention during setup and configuration.
2026-02-22 00:17:55 +03:00

91 lines
2.5 KiB
PowerShell

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# Load shared utilities
$utilsPath = Join-Path $PSScriptRoot '..\lib\utils.ps1'
. $utilsPath
.\scripts\Windows\starter.ps1
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
# Generate Prometheus web config from .env
Write-Step "Generating Prometheus web config..."
New-PrometheusWebConfig
# Shutdown services
Write-Step "Shutting down..."
$output = docker compose down 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Failed to shut down services"
Write-Host $output
exit $LASTEXITCODE
}
Write-Success "Services were shut down successfully!"
# Rebuild and start services
Write-Step "Spinning services up with rebuild..."
$output = docker compose up -d --build --wait 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Failed to start services"
Write-Host $output
exit $LASTEXITCODE
}
Write-Success "Services are up and healthy!"
# Run pre-run tasks
Write-Step "Completing pre-run tasks..."
Write-Info " Running migrations..."
$output = docker compose exec -T app uv run manage.py migrate --no-input --verbosity 0 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Migrations failed"
Write-Host $output
exit $LASTEXITCODE
}
Write-Info " Initializing..."
$output = docker compose exec -T app uv run manage.py initialize 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Initialization failed"
Write-Host $output
exit $LASTEXITCODE
}
Write-Info " Setting default caches..."
$output = docker compose exec -T app uv run manage.py set_default_caches 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Cache setup failed"
Write-Host $output
exit $LASTEXITCODE
}
Write-Info " Rebuilding search index..."
$output = docker compose exec -T app uv run manage.py search_index --rebuild -f 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Search index rebuild failed"
Write-Host $output
exit $LASTEXITCODE
}
Write-Info " Collecting static files..."
$output = docker compose exec -T app uv run manage.py collectstatic --clear --no-input --verbosity 0 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Error-Custom "Static files collection failed"
Write-Host $output
exit $LASTEXITCODE
}
Write-Success "Pre-run tasks completed successfully!"
# Cleanup
Write-Step "Cleaning up unused Docker data..."
docker system prune -f *>$null
if ($LASTEXITCODE -ne 0) {
Write-Warning-Custom "Docker cleanup had issues, but continuing..."
}
Write-Success "Unused Docker data cleaned successfully!"
Write-Result ""
Write-Result "All done! Schon is up and running!"