43 lines
1.4 KiB
Bash
Executable File
43 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
if [[ ${EUID} -ne 0 ]]; then
|
|
printf '%s\n' "reset-data must run as root" >&2
|
|
exit 1
|
|
fi
|
|
exec 9>/run/lock/harbor-release.lock
|
|
if ! flock -n 9; then
|
|
printf '%s\n' "another release or rollback is in progress" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "${1:-}" != "--yes" ]]; then
|
|
printf '%s\n' "usage: reset-data.sh --yes" >&2
|
|
printf '%s\n' "this permanently deletes all Mongo, Redis, and MinIO data" >&2
|
|
exit 1
|
|
fi
|
|
|
|
compose=(docker compose --env-file /etc/harbor/harbor.env -f /opt/harbor/deploy/compose/docker-compose.yml)
|
|
|
|
printf '%s\n' "stopping app slots"
|
|
for slot in blue green; do
|
|
systemctl stop "harbor-gateway@$slot.service" 2>/dev/null || true
|
|
systemctl stop "harbor-worker@$slot.service" 2>/dev/null || true
|
|
done
|
|
|
|
printf '%s\n' "stopping data services"
|
|
"${compose[@]}" stop mongo redis minio
|
|
"${compose[@]}" rm -f mongo redis minio
|
|
|
|
printf '%s\n' "removing data volumes"
|
|
docker volume rm haixun-prod_mongo_data haixun-prod_mongo_config haixun-prod_redis_data haixun-prod_minio_data
|
|
|
|
printf '%s\n' "recreating empty data services"
|
|
"${compose[@]}" up -d --wait --wait-timeout 180 mongo redis minio
|
|
|
|
rm -f /etc/harbor/admin-seeded /etc/harbor/initial-admin-credentials
|
|
|
|
printf '%s\n' "data reset complete: mongo/redis/minio are now empty"
|
|
printf '%s\n' "monitoring volumes (prometheus/grafana/loki/alertmanager) were left untouched"
|
|
printf '%s\n' "next: run release.sh to redeploy app code, run forward migrations, and reseed the admin account"
|