Files
mtusi2026lab2/scripts/restart.sh

19 lines
632 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
snapshot() {
for service in api postgres redis; do
id=$(docker compose ps -q "$service")
test -n "$id"
docker inspect --format '{{.Name}} {{.Id}} {{.State.StartedAt}} {{.State.Status}} {{range .Mounts}}{{if eq .Type "volume"}}{{.Name}} {{end}}{{end}}' "$id"
done
}
snapshot > evidence/restart-containers-before.txt
docker compose stop api postgres redis
docker compose up -d --wait postgres redis
docker compose up -d --wait api
snapshot > evidence/restart-containers-after.txt
printf '%s\n' 'API, PostgreSQL and Redis restarted without removing volumes.'