-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdev
More file actions
executable file
·94 lines (75 loc) · 2.23 KB
/
dev
File metadata and controls
executable file
·94 lines (75 loc) · 2.23 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
#!/usr/bin/env bash
# frozen_string_literal: true
set -e
# Load .env if exists
if [ -f .env ]; then
export $(cat .env | grep -v '^#' | xargs)
fi
export RACK_ENV=${RACK_ENV:-development}
# BusyBox lsof in this image reports internal FDs and exits 0, so prefer netstat.
port_in_use() {
netstat -ltn 2>/dev/null | awk '{print $4}' | grep -Eq "[:.]$1$"
}
# Cleanup function for graceful shutdown
cleanup() {
echo ""
echo "🛑 Shutting down development servers..."
# Kill Ruby server
if [ ! -z "$RUBY_PID" ]; then
kill $RUBY_PID 2>/dev/null || true
wait $RUBY_PID 2>/dev/null || true
fi
# Kill frontend dev server and its children
if [ ! -z "$FRONTEND_PID" ]; then
# Kill the frontend package-manager process and its children
pkill -P $FRONTEND_PID 2>/dev/null || true
kill $FRONTEND_PID 2>/dev/null || true
wait $FRONTEND_PID 2>/dev/null || true
fi
# Clean up any remaining processes on our ports
pkill -f "puma.*html2rss-web" 2>/dev/null || true
pkill -f "vite.*4001" 2>/dev/null || true
echo "✅ Development servers stopped"
exit 0
}
trap cleanup SIGINT SIGTERM
# Prevent silent failures from port conflicts
if port_in_use 4000; then
echo "❌ Port 4000 is already in use. Run: \`pkill -f 'puma.*html2rss-web'\`"
exit 1
fi
# Start Ruby server
bundle exec puma -p 4000 -C config/puma.rb &
RUBY_PID=$!
# Verify Ruby server started successfully (allow slower boots in containers)
RUBY_STARTUP_TIMEOUT=${RUBY_STARTUP_TIMEOUT:-30}
ruby_started=false
for _ in $(seq 1 "$RUBY_STARTUP_TIMEOUT"); do
if ! kill -0 $RUBY_PID 2>/dev/null; then
echo "❌ Ruby server failed to start"
exit 1
fi
if port_in_use 4000; then
ruby_started=true
break
fi
sleep 1
done
if [ "$ruby_started" != "true" ]; then
echo "❌ Ruby server did not start listening on port 4000 within ${RUBY_STARTUP_TIMEOUT}s"
kill $RUBY_PID 2>/dev/null || true
exit 1
fi
# Start frontend dev server
cd frontend
pnpm run dev &
FRONTEND_PID=$!
# Verify frontend server started
sleep 3
if ! kill -0 $FRONTEND_PID 2>/dev/null; then
echo "❌ Frontend dev server failed to start"
kill $RUBY_PID 2>/dev/null || true
exit 1
fi
echo "✅ Development environment ready at http://localhost:4001"
wait $RUBY_PID $FRONTEND_PID