-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdown.sh
More file actions
executable file
·154 lines (136 loc) · 5.57 KB
/
down.sh
File metadata and controls
executable file
·154 lines (136 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
set -euo pipefail
# Local Dev — Down
#
# Tears down everything up.sh started: services, containers, generated env
# files, log files, and the .local-dev-state file written by setup-c.sh /
# setup-pp.sh.
#
# This is "nuclear cleanup" — when you re-run up.sh you get a clean slate
# (fresh Stellar ledger, empty databases, no contracts, no PPs). Run setup-c
# and setup-pp again to repopulate the application state.
#
# Usage: ./down.sh
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BASE_DIR="${BASE_DIR:-$(dirname "$SCRIPT_DIR")}"
PROVIDER_PLATFORM_PATH="${PROVIDER_PLATFORM_PATH:-$BASE_DIR/provider-platform}"
COUNCIL_PLATFORM_PATH="${COUNCIL_PLATFORM_PATH:-$BASE_DIR/council-platform}"
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
# Ports & names — must match the values used in up.sh
PROVIDER_PORT="${PROVIDER_PORT:-3010}"
COUNCIL_PLATFORM_PORT="${COUNCIL_PLATFORM_PORT:-3015}"
PROVIDER_CONSOLE_PORT="${PROVIDER_CONSOLE_PORT:-3020}"
PAY_PLATFORM_PORT="${PAY_PLATFORM_PORT:-3025}"
COUNCIL_CONSOLE_PORT="${COUNCIL_CONSOLE_PORT:-3030}"
MOONLIGHT_PAY_PORT="${MOONLIGHT_PAY_PORT:-3050}"
NETWORK_DASHBOARD_PORT="${NETWORK_DASHBOARD_PORT:-3040}"
PG_CONTAINER="${PG_CONTAINER:-provider-platform-db}"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${GREEN}[INFO]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
# --- Helper: stop a process by PID file or port ---
stop_process() {
local name=$1
local pid_file=$2
local port=$3
local killed=false
if [ -f "$pid_file" ]; then
local pid
pid=$(cat "$pid_file")
if kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null
info "Stopped $name (PID $pid)"
killed=true
fi
rm "$pid_file"
fi
if [ "$killed" = false ]; then
for pid in $(lsof -ti :"$port" 2>/dev/null || true); do
if ps -p "$pid" -o command= 2>/dev/null | grep -q deno; then
kill "$pid" 2>/dev/null
info "Stopped deno process on port $port (PID $pid)"
fi
done
fi
}
# --- Stop all processes ---
stop_process "provider-platform" "$SCRIPT_DIR/.provider.pid" "$PROVIDER_PORT"
stop_process "council-platform" "$SCRIPT_DIR/.council-platform.pid" "$COUNCIL_PLATFORM_PORT"
stop_process "pay-platform" "$SCRIPT_DIR/.pay-platform.pid" "$PAY_PLATFORM_PORT"
stop_process "provider-console" "$SCRIPT_DIR/.provider-console.pid" "$PROVIDER_CONSOLE_PORT"
stop_process "council-console" "$SCRIPT_DIR/.council-console.pid" "$COUNCIL_CONSOLE_PORT"
stop_process "moonlight-pay" "$SCRIPT_DIR/.moonlight-pay.pid" "$MOONLIGHT_PAY_PORT"
stop_process "network-dashboard" "$SCRIPT_DIR/.network-dashboard.pid" "$NETWORK_DASHBOARD_PORT"
# --- Stop PostgreSQL container ---
if docker ps -a --format '{{.Names}}' | grep -q "^${PG_CONTAINER}$"; then
docker rm -f "$PG_CONTAINER" >/dev/null 2>&1
info "Stopped PostgreSQL ($PG_CONTAINER)"
fi
# --- Stop Jaeger container ---
JAEGER_CONTAINER="${JAEGER_CONTAINER:-jaeger}"
if docker ps -a --format '{{.Names}}' | grep -q "^${JAEGER_CONTAINER}$"; then
docker rm -f "$JAEGER_CONTAINER" >/dev/null 2>&1
info "Stopped Jaeger ($JAEGER_CONTAINER)"
fi
# --- Clean up generated files ---
# Note: up.sh no longer creates Stellar keys (account creation moved to
# setup-c.sh / setup-pp.sh, which use ephemeral keys per run — nothing to
# remove from the stellar CLI keyring).
PAY_PLATFORM_PATH="${PAY_PLATFORM_PATH:-$BASE_DIR/pay-platform}"
for f in \
"$PROVIDER_PLATFORM_PATH/.env" \
"$COUNCIL_PLATFORM_PATH/.env" \
"$PAY_PLATFORM_PATH/.env" \
"$SCRIPT_DIR/.local-dev-state" \
"$SCRIPT_DIR/provider.log" \
"$SCRIPT_DIR/council-platform.log" \
"$SCRIPT_DIR/pay-platform.log" \
"$SCRIPT_DIR/provider-console.log" \
"$SCRIPT_DIR/council-console.log" \
"$SCRIPT_DIR/moonlight-pay.log" \
"$SCRIPT_DIR/network-dashboard.log" \
; do
if [ -f "$f" ]; then
rm "$f"
info "Removed $f"
fi
done
# --- Wipe Deno KV stores ---
# Both platforms persist event-watcher cursors and other state in
# ./.data/memory-kvdb.db relative to their working directory. This file
# survives docker/postgres teardown and would otherwise carry stale ledger
# cursors into the next up cycle (event watcher tries to poll a ledger
# that no longer exists on the freshly-launched Stellar quickstart).
for d in \
"$PROVIDER_PLATFORM_PATH/.data" \
"$COUNCIL_PLATFORM_PATH/.data" \
; do
if [ -d "$d" ]; then
rm -rf "$d"
info "Removed $d"
fi
done
# --- Stop the Stellar quickstart container started by `stellar container start local`.
# This is the same container up.sh launches via the Stellar CLI. Without this
# step, `down → up` reuses the same ledger state — which masks bugs in
# scripts that assume a fresh ledger and breaks deterministic deploys
# (the contracts setup-c.sh deploys at fixed addresses already exist).
if command -v stellar >/dev/null 2>&1; then
stellar container stop local >/dev/null 2>&1 && info "Stopped Stellar container (stellar-local)" || true
fi
# Belt-and-braces: also force-remove anything that matches the
# stellar-local container name in case the CLI subcommand failed.
if docker ps -a --format '{{.Names}}' | grep -q "^stellar-local$"; then
docker rm -f stellar-local >/dev/null 2>&1 && info "Force-removed stellar-local container" || true
fi
# --- Tear down lifecycle Docker Compose if running ---
if [ -f "$SCRIPT_DIR/lifecycle/docker-compose.yml" ]; then
docker compose -f "$SCRIPT_DIR/lifecycle/docker-compose.yml" down 2>/dev/null && info "Stopped lifecycle containers" || true
fi
# --- Clean up old pid files (backward compat) ---
rm -f "$SCRIPT_DIR/.console.pid" "$SCRIPT_DIR/console.log" 2>/dev/null
echo ""
info "Down. All services stopped."