36 lines
700 B
Bash
36 lines
700 B
Bash
#!/usr/bin/env bash
|
|
|
|
set -Eeuo pipefail
|
|
|
|
uvicorn --app-dir /app app.main:app \
|
|
--host 127.0.0.1 \
|
|
--port 8000 \
|
|
--workers 1 &
|
|
backend_pid=$!
|
|
|
|
nginx -g "daemon off;" &
|
|
nginx_pid=$!
|
|
|
|
stop_children() {
|
|
kill -TERM "$backend_pid" "$nginx_pid" 2>/dev/null || true
|
|
wait "$backend_pid" 2>/dev/null || true
|
|
wait "$nginx_pid" 2>/dev/null || true
|
|
}
|
|
|
|
shutdown() {
|
|
trap - TERM INT
|
|
stop_children
|
|
exit 143
|
|
}
|
|
|
|
trap shutdown TERM INT
|
|
|
|
# If either service exits, stop the other one and let Docker restart/report the
|
|
# container rather than leaving a partially working instance running.
|
|
set +e
|
|
wait -n "$backend_pid" "$nginx_pid"
|
|
exit_code=$?
|
|
set -e
|
|
|
|
stop_children
|
|
exit "$exit_code"
|