feat: add script for graceful shutdown and process cleanup

- Introduced a new script `dev-kill-all.sh` to handle graceful shutdown of development processes and cleanup of stale PID files.
- Updated Makefile to include a `kill` command that utilizes the new script for improved process management.
- Enhanced the shutdown process to verify that required ports are free after termination of processes.
This commit is contained in:
anonpenguin23 2025-11-10 06:41:44 +02:00
parent 17fc78975d
commit 170665bf02
No known key found for this signature in database
GPG Key ID: 1CBB1FE35AFBEE30
3 changed files with 89 additions and 2 deletions

View File

@ -13,6 +13,21 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant
### Deprecated
### Fixed
## [0.63.0] - 2025-11-10
### Added
- Added a new `kill` command to the Makefile for forcefully shutting down all development processes.
- Introduced a new `stop` command in the Makefile for graceful shutdown of development processes.
### Changed
- The `kill` command now performs a graceful shutdown attempt followed by a force kill of any lingering processes and verifies that development ports are free.
### Deprecated
### Removed
### Fixed
\n
## [0.62.0] - 2025-11-10
### Added

View File

@ -21,7 +21,7 @@ test-e2e:
.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports install-hooks kill
VERSION := 0.62.0
VERSION := 0.63.0
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
@ -87,8 +87,11 @@ run-gateway:
dev: build
@./bin/dbn dev up
# Kill all processes using dbn dev down
# Kill all processes (graceful shutdown + force kill stray processes)
kill:
@bash scripts/dev-kill-all.sh
stop:
@./bin/dbn dev down
# Help

69
scripts/dev-kill-all.sh Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BIN_DBN="$ROOT_DIR/bin/dbn"
# First, try graceful shutdown via dbn dev down
if [[ -x "$BIN_DBN" ]]; then
echo "Attempting graceful shutdown via dbn dev down..."
"$BIN_DBN" dev down || true
sleep 1
fi
# Clean up PID files
PIDS_DIR="$HOME/.debros/.pids"
if [[ -d "$PIDS_DIR" ]]; then
echo "Removing stale PID files..."
rm -f "$PIDS_DIR"/*.pid || true
fi
# Force kill any lingering processes
echo "Force killing any remaining dev processes..."
declare -a PATTERNS=(
"ipfs daemon"
"ipfs-cluster-service daemon"
"rqlited"
"olric-server"
"anyone-client"
"bin/node"
"bin/gateway"
)
killed_count=0
for pattern in "${PATTERNS[@]}"; do
count=$(pgrep -f "$pattern" | wc -l)
if [[ $count -gt 0 ]]; then
pkill -f "$pattern" || true
echo "✓ Killed $count process(es) matching: $pattern"
killed_count=$((killed_count + count))
fi
done
if [[ $killed_count -eq 0 ]]; then
echo "✓ No lingering dev processes found"
else
echo "✓ Terminated $killed_count process(es) total"
sleep 1
fi
# Verify ports are free
echo ""
echo "Verifying ports are now available..."
PORTS=(4001 4501 4502 4503 5001 5002 5003 6001 7001 7002 7003 9094 9104 9114 3320 3322 9050)
unavailable=()
for port in "${PORTS[@]}"; do
if lsof -nP -iTCP:"$port" -sTCP:LISTEN >/dev/null 2>&1; then
unavailable+=("$port")
fi
done
if [[ ${#unavailable[@]} -eq 0 ]]; then
echo "✓ All required ports are free"
else
echo "⚠️ WARNING: These ports are still in use: ${unavailable[*]}"
echo "Use 'lsof -nP -i :PORT' to identify the processes"
fi