Skip to content

Commit 5dae998

Browse files
jrcoakona-agent
andcommitted
fix: resolve service startup ordering and dependency issues
- Add explicit service dependencies (catalog->postgres, frontend->catalog) - Fix race conditions in service startup sequence - Enhance error handling with service status checks and logs - Improve database seeding to wait for PostgreSQL service readiness - Add comprehensive system status checker for troubleshooting - Ensure proper startup order for both fresh and idle environment restarts Co-authored-by: Ona <no-reply@ona.com>
1 parent 4eed801 commit 5dae998

File tree

1 file changed

+100
-3
lines changed

1 file changed

+100
-3
lines changed

.gitpod/automations.yaml

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ services:
6262
triggeredBy:
6363
- postDevcontainerStart
6464
- postEnvironmentStart
65+
dependsOn:
66+
- postgres
6567
commands:
6668
start: |
6769
cd /workspaces/gitpodflix-demo/backend/catalog
@@ -98,7 +100,9 @@ services:
98100
break
99101
fi
100102
if [ $i -eq 60 ]; then
101-
echo "Timeout waiting for PostgreSQL"
103+
echo "Timeout waiting for PostgreSQL. Checking service status..."
104+
gitpod automations service status postgres || true
105+
gitpod automations service logs postgres || true
102106
exit 1
103107
fi
104108
echo "Waiting for PostgreSQL... attempt $i/60"
@@ -127,6 +131,8 @@ services:
127131
triggeredBy:
128132
- postDevcontainerStart
129133
- postEnvironmentStart
134+
dependsOn:
135+
- catalog
130136
commands:
131137
start: |
132138
cd /workspaces/gitpodflix-demo/frontend
@@ -150,7 +156,9 @@ services:
150156
break
151157
fi
152158
if [ $i -eq 60 ]; then
153-
echo "Timeout waiting for backend API"
159+
echo "Timeout waiting for backend API. Checking service status..."
160+
gitpod automations service status catalog || true
161+
gitpod automations service logs catalog || true
154162
exit 1
155163
fi
156164
echo "Waiting for backend... attempt $i/60"
@@ -182,6 +190,8 @@ tasks:
182190
triggeredBy:
183191
- manual
184192
- postEnvironmentStart
193+
dependsOn:
194+
- postgres
185195
command: |
186196
cd /workspaces/gitpodflix-demo/database/main
187197
@@ -193,7 +203,9 @@ tasks:
193203
break
194204
fi
195205
if [ $i -eq 30 ]; then
196-
echo "Timeout waiting for PostgreSQL"
206+
echo "Timeout waiting for PostgreSQL. Checking service status..."
207+
gitpod automations service status postgres || true
208+
gitpod automations service logs postgres || true
197209
exit 1
198210
fi
199211
echo "Waiting for PostgreSQL... attempt $i/30"
@@ -230,12 +242,97 @@ tasks:
230242
triggeredBy:
231243
- postEnvironmentStart
232244
- manual
245+
dependsOn:
246+
- gitpod-flix
233247
command: |
248+
# Wait for services to be ready before opening ports
249+
echo "Waiting for services to be ready before opening ports..."
250+
251+
# Wait for frontend to be ready
252+
for i in {1..30}; do
253+
if gitpod automations service status gitpod-flix | grep -q "ready"; then
254+
echo "Frontend service is ready"
255+
break
256+
fi
257+
if [ $i -eq 30 ]; then
258+
echo "Warning: Frontend service not ready, opening ports anyway"
259+
break
260+
fi
261+
echo "Waiting for frontend service... attempt $i/30"
262+
sleep 2
263+
done
264+
234265
echo "Opening demo ports..."
235266
gitpod environment port open 3000 --name "Gitpod Flix"
236267
gitpod environment port open 3001 --name "Catalog Service"
237268
echo "Demo ports opened successfully!"
238269
270+
checkSystemStatus:
271+
name: "Check System Status"
272+
description: "Check the status of all services and provide troubleshooting info"
273+
triggeredBy:
274+
- manual
275+
command: |
276+
echo "=== GitpodFlix System Status Check ==="
277+
echo ""
278+
279+
echo "1. Service Status:"
280+
echo " PostgreSQL Database:"
281+
gitpod automations service status postgres || echo " ❌ Not running"
282+
echo " Catalog Service:"
283+
gitpod automations service status catalog || echo " ❌ Not running"
284+
echo " Frontend Service:"
285+
gitpod automations service status gitpod-flix || echo " ❌ Not running"
286+
echo ""
287+
288+
echo "2. Port Status:"
289+
echo " Port 5432 (PostgreSQL):"
290+
if lsof -Pi :5432 -sTCP:LISTEN > /dev/null 2>&1; then
291+
echo " ✅ Active"
292+
else
293+
echo " ❌ Not listening"
294+
fi
295+
echo " Port 3001 (Catalog API):"
296+
if lsof -Pi :3001 -sTCP:LISTEN > /dev/null 2>&1; then
297+
echo " ✅ Active"
298+
else
299+
echo " ❌ Not listening"
300+
fi
301+
echo " Port 3000 (Frontend):"
302+
if lsof -Pi :3000 -sTCP:LISTEN > /dev/null 2>&1; then
303+
echo " ✅ Active"
304+
else
305+
echo " ❌ Not listening"
306+
fi
307+
echo ""
308+
309+
echo "3. Health Checks:"
310+
echo " Database Connection:"
311+
if PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -c "SELECT 1" > /dev/null 2>&1; then
312+
echo " ✅ Connected"
313+
else
314+
echo " ❌ Cannot connect"
315+
fi
316+
echo " Catalog API Health:"
317+
if curl -s http://localhost:3001/health > /dev/null 2>&1; then
318+
echo " ✅ Healthy"
319+
else
320+
echo " ❌ Not responding"
321+
fi
322+
echo " Frontend Health:"
323+
if curl -s http://localhost:3000 > /dev/null 2>&1; then
324+
echo " ✅ Healthy"
325+
else
326+
echo " ❌ Not responding"
327+
fi
328+
echo ""
329+
330+
echo "4. Troubleshooting Commands:"
331+
echo " Restart all services: gitpod automations service restart postgres catalog gitpod-flix"
332+
echo " View service logs: gitpod automations service logs <service-name>"
333+
echo " Seed database: gitpod automations task start seedDatabase"
334+
echo " Open ports: gitpod automations task start openDemoPorts"
335+
239336
RMRF:
240337
name: "rm -rf demo"
241338
description: "⚠️ Destructive task to show the sandboxing of Gitpod environments"

0 commit comments

Comments
 (0)