Files
cpa-plugin/scripts/stop-test-host.sh
T

26 lines
573 B
Bash

#!/usr/bin/env bash
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
pid_file="$root/.runtime/cpa.pid"
if [[ ! -f "$pid_file" ]]; then
echo 'CPA test host is not running.'
exit 0
fi
pid="$(cat "$pid_file")"
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
kill "$pid"
for _ in $(seq 1 20); do
kill -0 "$pid" 2>/dev/null || break
sleep 0.25
done
if kill -0 "$pid" 2>/dev/null; then
echo "CPA test host did not stop within 5 seconds (PID $pid)." >&2
exit 1
fi
fi
rm -f "$pid_file"
echo 'CPA test host stopped.'