mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-12-13 02:48:49 +00:00
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:
parent
17fc78975d
commit
170665bf02
15
CHANGELOG.md
15
CHANGELOG.md
@ -13,6 +13,21 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant
|
|||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
### Fixed
|
### 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
|
## [0.62.0] - 2025-11-10
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
7
Makefile
7
Makefile
@ -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
|
.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)
|
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'
|
||||||
@ -87,8 +87,11 @@ run-gateway:
|
|||||||
dev: build
|
dev: build
|
||||||
@./bin/dbn dev up
|
@./bin/dbn dev up
|
||||||
|
|
||||||
# Kill all processes using dbn dev down
|
# Kill all processes (graceful shutdown + force kill stray processes)
|
||||||
kill:
|
kill:
|
||||||
|
@bash scripts/dev-kill-all.sh
|
||||||
|
|
||||||
|
stop:
|
||||||
@./bin/dbn dev down
|
@./bin/dbn dev down
|
||||||
|
|
||||||
# Help
|
# Help
|
||||||
|
|||||||
69
scripts/dev-kill-all.sh
Executable file
69
scripts/dev-kill-all.sh
Executable 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
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user