schon/scripts/Unix/reboot.sh
Egor fureunoir Gorbunov d8bc92ced0 Features: 1) Add error handling for subprocess execution with non-zero exit codes; 2) Update service messages for better clarity.
Fixes: 1) Ensure `run_with_spinner` handles subprocess errors gracefully by setting and resetting execution flags; 2) Prevent script termination on `docker compose down` failures.

Extra: 1) Improve inline comments and messaging; 2) Minor adjustments to enhance script maintainability.
2025-06-16 14:13:40 +03:00

46 lines
1.4 KiB
Bash
Executable file

#!/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
set +e
wait "$pid"
local rc=$?
set -e
if [[ $rc -ne 0 ]]; then
printf "\e[33m(! exit %d)\e[0m " "$rc"
fi
printf "\e[32m✔\e[0m\n"
}
echo
run_with_spinner "docker compose --ansi never down || true" "Stopping services"
run_with_spinner "docker compose --ansi never up -d --build" "Rebuilding & starting services"
run_with_spinner "docker compose --ansi never exec app poetry run python manage.py migrate --no-input" "Applying database migrations"
run_with_spinner "docker compose --ansi never exec app poetry run python manage.py collectstatic --no-input" "Collecting static files"
run_with_spinner "docker compose --ansi never 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"