#!/usr/bin/env bash
# stop_all.sh — Zastaví všechny dev-env služby
set -euo pipefail

DEV_ENV_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PID_DIR="${DEV_ENV_DIR}/.pids"

echo "=== Zastavování dev-env služeb ==="

for pid_file in "${PID_DIR}"/*.pid; do
    if [[ -f "${pid_file}" ]]; then
        name="$(basename "${pid_file}" .pid)"
        pid="$(cat "${pid_file}")"
        if kill -0 "${pid}" 2>/dev/null; then
            kill "${pid}" 2>/dev/null || true
            echo "Zastaveno: ${name} (PID: ${pid})"
        else
            echo "Nebeží: ${name}"
        fi
        rm -f "${pid_file}"
    fi
done

echo "=== Vše zastaveno ==="