From fb4eb79427d17d47869526d6853e95b80aae67f2 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Mon, 16 Jun 2025 14:02:30 +0300 Subject: [PATCH] Features: 1) Add reboot scripts for Windows (PowerShell) and Unix (Bash) to streamline service management and data cleanup; Fixes: None; Extra: 1) Add spinner animations and color-coded output for improved user feedback. --- scripts/Unix/reboot.sh | 39 +++++++++++++++++++++++++ scripts/Windows/reboot.ps1 | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 scripts/Unix/reboot.sh create mode 100644 scripts/Windows/reboot.ps1 diff --git a/scripts/Unix/reboot.sh b/scripts/Unix/reboot.sh new file mode 100644 index 00000000..c73934b7 --- /dev/null +++ b/scripts/Unix/reboot.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SPINNER=('|' '/' '-' '\\') +COLORS=(97 37 90) +DELAY=0.1 + +run_with_spinner() { + local cmd="$1" + local msg="$2" + + printf "\e[1m%s...\e[0m " "$msg" + eval "$cmd" &> /dev/null & + local pid=$! + + local i=0 + while kill -0 "$pid" 2>/dev/null; do + local frame=${SPINNER[i % ${#SPINNER[@]}]} + local color=${COLORS[i % ${#COLORS[@]}]} + printf "\e[${color}m%s\e[0m" "$frame" + sleep "$DELAY" + printf "\b" + ((i++)) + done + + wait "$pid" + printf "\e[32m✔\e[0m\n" +} + +echo +run_with_spinner "docker compose down --ansi never" "Stopping services (down)" +run_with_spinner "docker compose up -d --build --ansi never" "Rebuilding & starting services" +run_with_spinner "docker compose exec app poetry run python manage.py migrate --no-input" "Applying database migrations" +run_with_spinner "docker compose exec app poetry run python manage.py collectstatic --no-input" "Collecting static files" +run_with_spinner "docker compose exec app poetry run python manage.py set_default_caches" "Setting default caches" +run_with_spinner "docker system prune -f" "Cleaning up unused Docker data" + +echo -e "\e[1mAll done! Your application is up and running.\e[0m" diff --git a/scripts/Windows/reboot.ps1 b/scripts/Windows/reboot.ps1 new file mode 100644 index 00000000..915b44fa --- /dev/null +++ b/scripts/Windows/reboot.ps1 @@ -0,0 +1,58 @@ +$ErrorActionPreference = 'Stop' + +$Spinner = @('|', '/', '-', '\') +$Colors = @('White', 'Gray') +$Delay = 100 + +function Invoke-Spinner +{ + [CmdletBinding()] + param( + [Parameter(Mandatory)] + [string]$Arguments, + + [Parameter(Mandatory)] + [string]$Message + ) + + Write-Host -NoNewLine -ForegroundColor Cyan ("{0}... " -f $Message) + + $startInfo = New-Object System.Diagnostics.ProcessStartInfo + $startInfo.FileName = "docker" + $startInfo.Arguments = $Arguments + " --ansi never" + $startInfo.RedirectStandardOutput = $true + $startInfo.RedirectStandardError = $true + $startInfo.UseShellExecute = $false + + $proc = [System.Diagnostics.Process]::Start($startInfo) + + $i = 0 + while (-not $proc.HasExited) + { + $frame = $Spinner[$i % $Spinner.Length] + $color = $Colors[$i % $Colors.Length] + Write-Host -NoNewLine -ForegroundColor $color $frame + Start-Sleep -Milliseconds $Delay + Write-Host -NoNewLine "`b" + $i++ + } + $proc.WaitForExit() + + Write-Host -ForegroundColor Green "✔" +} + +Write-Host "" +Invoke-Spinner -Arguments "compose down" ` + -Message "Stopping services (down)" +Invoke-Spinner -Arguments "compose up -d --build" ` + -Message "Rebuilding & starting services" +Invoke-Spinner -Arguments "compose exec app poetry run python manage.py migrate --no-input" ` + -Message "Applying database migrations" +Invoke-Spinner -Arguments "compose exec app poetry run python manage.py collectstatic --no-input" ` + -Message "Collecting static files" +Invoke-Spinner -Arguments "compose exec app poetry run python manage.py set_default_caches" ` + -Message "Setting default caches" +Invoke-Spinner -Arguments "system prune -f" ` + -Message "Cleaning up unused Docker data" + +Write-Host "`nAll done! Your application is up and running." -ForegroundColor White