66 lines
1.6 KiB
Bash
Executable File
66 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
# shellcheck source=./lib.sh
|
|
source "$SCRIPT_DIR/lib.sh"
|
|
|
|
ENV_FILE="$SCRIPT_DIR/stack.env"
|
|
AUTO_YES=false
|
|
REMOVE_DATA=false
|
|
|
|
usage() {
|
|
cat <<USAGE
|
|
Usage: $(basename "$0") [options]
|
|
|
|
Stop and remove monitoring stack containers.
|
|
|
|
Options:
|
|
--env-file=PATH Env file path (default: setup/pi-monitoring/stack.env)
|
|
--remove-data Also remove data directories under OPS_ROOT (destructive)
|
|
--yes, -y Skip confirmation prompt
|
|
--help, -h Show help
|
|
USAGE
|
|
}
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--env-file=*) ENV_FILE="${arg#*=}" ;;
|
|
--remove-data) REMOVE_DATA=true ;;
|
|
--yes|-y) AUTO_YES=true ;;
|
|
--help|-h) usage; exit 0 ;;
|
|
*) log_error "Unknown argument: $arg"; usage; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
require_cmd docker
|
|
load_stack_env "$ENV_FILE"
|
|
compose_file_path="$(compose_file)"
|
|
|
|
if ! confirm_action "Tear down monitoring stack containers?" "$AUTO_YES"; then
|
|
log_info "Cancelled"
|
|
exit 0
|
|
fi
|
|
|
|
log_info "Stopping/removing compose services..."
|
|
docker compose \
|
|
--project-name "$COMPOSE_PROJECT_NAME" \
|
|
--env-file "$ENV_FILE" \
|
|
-f "$compose_file_path" \
|
|
down
|
|
|
|
if [[ "$REMOVE_DATA" == "true" ]]; then
|
|
if ! confirm_action "Remove data under ${OPS_ROOT}/{portainer,grafana,prometheus,uptime-kuma}?" "$AUTO_YES"; then
|
|
log_info "Data removal skipped"
|
|
else
|
|
sudo rm -rf \
|
|
"$OPS_ROOT/portainer" \
|
|
"$OPS_ROOT/grafana" \
|
|
"$OPS_ROOT/prometheus" \
|
|
"$OPS_ROOT/uptime-kuma"
|
|
log_success "Data directories removed"
|
|
fi
|
|
fi
|
|
|
|
log_success "Teardown complete"
|