-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·201 lines (181 loc) · 6.1 KB
/
start.sh
File metadata and controls
executable file
·201 lines (181 loc) · 6.1 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
set -e
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
INGEST_PID_FILE="$ROOT_DIR/.ingest.pid"
ADMIN_PID_FILE="$ROOT_DIR/.admin.pid"
usage() {
echo "Event Processing Platform"
echo ""
echo "Usage: ./start.sh [command]"
echo ""
echo "Commands:"
echo " start Build and start ingest + admin locally (default)"
echo " stop Stop all local services"
echo " restart Stop then start"
echo " status Show running services"
echo " build Build all modules without starting"
echo " test Run all tests"
echo " docker Start Kafka, PostgreSQL, ingest, admin with Docker"
echo " docker-stop Stop Docker Compose services"
echo " engine <name> Start an engine instance for a pipeline (Docker)"
echo " engine-stop <name> Stop an engine instance"
echo " engines List running engine instances"
echo ""
echo "Ports:"
echo " Kafka: 9492 Ingest: 8090/9190 Admin: 8091 DB: 5877 UI: 3070"
echo ""
echo "Examples:"
echo " ./start.sh docker # start infrastructure"
echo " ./start.sh engine orders-to-warehouse # start engine for pipeline"
echo " ./start.sh engines # list running engines"
echo " ./start.sh engine-stop orders-to-warehouse"
echo " ./start.sh test # run all 39+ tests"
echo ""
}
build() {
echo "Building all modules..."
cd "$ROOT_DIR"
./mvnw package -DskipTests -q
echo "Build complete."
}
start_service() {
local name=$1
local dir=$2
local pid_file=$3
local port=$4
if [ -f "$pid_file" ] && kill -0 "$(cat "$pid_file")" 2>/dev/null; then
echo "$name already running (PID $(cat "$pid_file"))"
return
fi
echo "Starting $name..."
cd "$dir"
java -jar target/*.jar > "$ROOT_DIR/.$(echo "$name" | tr '[:upper:]' '[:lower:]').log" 2>&1 &
echo $! > "$pid_file"
if [ -n "$port" ]; then
echo "Waiting for $name on port $port..."
for i in $(seq 1 30); do
if curl -s "http://localhost:$port/api/health" > /dev/null 2>&1 || \
curl -s "http://localhost:$port/api/status" > /dev/null 2>&1; then
echo "$name started (PID $(cat "$pid_file"))"
return
fi
sleep 1
done
echo "$name may not have started. Check logs."
else
echo "$name started (PID $(cat "$pid_file"))"
fi
}
stop_service() {
local name=$1
local pid_file=$2
if [ -f "$pid_file" ]; then
local pid=$(cat "$pid_file")
if kill -0 "$pid" 2>/dev/null; then
kill "$pid"
echo "$name stopped (PID $pid)"
else
echo "$name not running"
fi
rm -f "$pid_file"
else
echo "$name not running"
fi
}
do_start() {
do_stop
build
start_service "event-ingest" "$ROOT_DIR/event-ingest" "$INGEST_PID_FILE" "8090"
start_service "event-admin" "$ROOT_DIR/event-admin" "$ADMIN_PID_FILE" "8091"
echo ""
echo "Infrastructure running:"
echo " Ingest: http://localhost:8090"
echo " Admin: http://localhost:8091"
echo " Swagger: http://localhost:8090/swagger-ui.html"
echo ""
echo "Next: create a pipeline via admin, then start an engine instance."
echo "Run ./start.sh stop to shut down."
}
do_stop() {
stop_service "event-admin" "$ADMIN_PID_FILE"
stop_service "event-ingest" "$INGEST_PID_FILE"
}
do_status() {
echo "Local services:"
for svc in ingest admin; do
pid_file="$ROOT_DIR/.$svc.pid"
if [ -f "$pid_file" ] && kill -0 "$(cat "$pid_file")" 2>/dev/null; then
echo " event-$svc: running (PID $(cat "$pid_file"))"
else
echo " event-$svc: stopped"
fi
done
echo ""
echo "Docker containers:"
cd "$ROOT_DIR"
docker compose ps 2>/dev/null || echo " Docker Compose not running"
}
do_docker() {
do_stop
echo "Starting with Docker Compose..."
cd "$ROOT_DIR"
docker compose up --build -d "$@"
}
do_docker_stop() {
cd "$ROOT_DIR"
docker compose down
}
do_engine_start() {
local pipeline_name=$1
if [ -z "$pipeline_name" ]; then
echo "Usage: ./start.sh engine <pipeline-name>"
echo ""
echo "Example: ./start.sh engine orders-to-warehouse"
exit 1
fi
echo "Starting engine for pipeline: $pipeline_name"
cd "$ROOT_DIR"
PIPELINE_NAME="$pipeline_name" docker compose run -d event-engine
echo "Engine started for pipeline: $pipeline_name"
}
do_engine_stop() {
local pipeline_name=$1
if [ -z "$pipeline_name" ]; then
echo "Usage: ./start.sh engine-stop <pipeline-name>"
exit 1
fi
echo "Stopping engine for pipeline: $pipeline_name"
cd "$ROOT_DIR"
docker ps --filter "label=com.docker.compose.service=event-engine" --format "{{.ID}} {{.Names}}" | while read id name; do
if docker exec "$id" printenv PIPELINE_NAME 2>/dev/null | grep -q "$pipeline_name"; then
docker stop "$id"
docker rm "$id"
echo "Stopped: $name"
return
fi
done
echo "No engine found for pipeline: $pipeline_name"
}
do_engines_list() {
echo "Running engine instances:"
cd "$ROOT_DIR"
docker ps --filter "label=com.docker.compose.service=event-engine" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null
if [ $? -ne 0 ] || [ -z "$(docker ps --filter 'label=com.docker.compose.service=event-engine' -q 2>/dev/null)" ]; then
echo " No engines running"
fi
}
case "${1:-start}" in
start) do_start ;;
stop) do_stop ;;
restart) do_stop; do_start ;;
status) do_status ;;
build) build ;;
test) cd "$ROOT_DIR" && ./mvnw test ;;
docker) shift; do_docker "$@" ;;
docker-stop) do_docker_stop ;;
engine) do_engine_start "$2" ;;
engine-stop) do_engine_stop "$2" ;;
engines) do_engines_list ;;
-h|--help|help) usage ;;
*) usage ;;
esac