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.
This commit is contained in:
parent
0da8bd77b0
commit
fb4eb79427
2 changed files with 97 additions and 0 deletions
39
scripts/Unix/reboot.sh
Normal file
39
scripts/Unix/reboot.sh
Normal file
|
|
@ -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"
|
||||||
58
scripts/Windows/reboot.ps1
Normal file
58
scripts/Windows/reboot.ps1
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue