-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
43 lines (35 loc) · 1.22 KB
/
Copy pathentrypoint.sh
File metadata and controls
43 lines (35 loc) · 1.22 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
#!/bin/bash
# Starts the Web API on loopback, waits for it to accept connections, then runs the MVC front
# end on the port the host assigns ($PORT on Cloud Run, 8080 otherwise). If either process dies
# the container exits so the platform replaces it with a clean one.
set -uo pipefail
API_PORT=5001
WEB_PORT="${PORT:-8080}"
echo "Starting Web API on 127.0.0.1:${API_PORT}"
# Each app runs from its own directory: ASP.NET Core takes the content root from the working
# directory, not from the assembly location, and it is what appsettings.json and wwwroot are
# resolved against.
(cd /app/api && ASPNETCORE_URLS="http://127.0.0.1:${API_PORT}" exec dotnet HotelProject.WebApi.dll) &
API_PID=$!
shutdown() {
kill -TERM "$API_PID" "${WEB_PID:-}" 2>/dev/null
}
trap shutdown TERM INT
for _ in $(seq 1 60); do
if ! kill -0 "$API_PID" 2>/dev/null; then
echo "Web API exited before it became ready" >&2
exit 1
fi
if nc -z 127.0.0.1 "$API_PORT"; then
echo "Web API is ready"
break
fi
sleep 0.5
done
echo "Starting Web UI on 0.0.0.0:${WEB_PORT}"
(cd /app/web && ASPNETCORE_URLS="http://0.0.0.0:${WEB_PORT}" exec dotnet HotelProject.WebUI.dll) &
WEB_PID=$!
wait -n "$API_PID" "$WEB_PID"
EXIT_CODE=$?
shutdown
exit "$EXIT_CODE"