Something went wrong. Try again.
An orchestrator running microVMs on demand. Built for AI agent sandboxes, CI engines, and more.
Something went wrong. Try again.
1.5 kB · 61 lines
Shell
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#!/usr/bin/env bashset -euo pipefail
# Finds the process holding the hyperfleet dev port and offers to stop it.# Usage: ./scripts/stop.sh [port] (defaults to 8080)
PORT="${1:-${PORT:-8080}}"
find_pid() { if command -v lsof >/dev/null 2>&1; then lsof -ti :"$1" 2>/dev/null | head -1 return fi if command -v ss >/dev/null 2>&1; then sudo ss -ltnp 2>/dev/null \ | awk -v p=":$1\$" '$4 ~ p { print $NF }' \ | grep -oE 'pid=[0-9]+' | head -1 | cut -d= -f2 return fi if command -v fuser >/dev/null 2>&1; then fuser "$1"/tcp 2>/dev/null | tr -s ' ' '\n' | grep -E '^[0-9]+$' | head -1 return fi echo "neither lsof, ss, nor fuser found" >&2 return 1}
PID="$(find_pid "$PORT" || true)"
if [[ -z "${PID}" ]]; then echo "nothing listening on :${PORT}" exit 0fi
echo "PID ${PID} is holding :${PORT}:"ps -p "${PID}" -o pid,user,etime,cmd 2>&1 | head -2
if command -v gum >/dev/null 2>&1; then gum confirm "Kill PID ${PID}?" || { echo "aborted"; exit 0; }else read -r -p "Kill PID ${PID}? [y/N] " ans [[ "${ans}" =~ ^[Yy]$ ]] || { echo "aborted"; exit 0; }fi
kill "${PID}" 2>/dev/null || truefor _ in 1 2 3 4 5; do if ! kill -0 "${PID}" 2>/dev/null; then echo "stopped" exit 0 fi sleep 0.4done
echo "still alive, sending SIGKILL"kill -9 "${PID}" 2>/dev/null || truesleep 0.5if kill -0 "${PID}" 2>/dev/null; then echo "could not stop PID ${PID}" >&2 exit 1fiecho "stopped"