-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlaunch.sh
More file actions
executable file
·75 lines (66 loc) · 2.21 KB
/
launch.sh
File metadata and controls
executable file
·75 lines (66 loc) · 2.21 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
#!/bin/bash
# launch.sh - Script to launch the web server in a bare-metal environment (non-Docker)
# Ensure the script runs relative to its own directory so .env/.venv are found reliably.
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Load .env (if present) and export values for this process.
if [ -f ".env" ]; then
set -a
# shellcheck disable=SC1091
source ".env"
set +a
fi
# Default values
VENV_PATH="${VENV_PATH:-.venv}"
PORT="${PORT:-5000}"
ACCESS_LOGFILE="${ACCESS_LOGFILE:-/dev/null}"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-p|--port)
PORT="$2"
shift 2
;;
-v|--venv)
VENV_PATH="$2"
shift 2
;;
-a|--access-logfile)
ACCESS_LOGFILE="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " -p, --port PORT Set the port (default: 5000)"
echo " -v, --venv PATH Set the virtual environment path (default: .venv)"
echo " -a, --access-logfile Hypercorn access log target (default: /dev/null, use '-' for stdout)"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use -h or --help for usage information"
exit 1
;;
esac
done
# Activate virtual environment
if [ ! -d "$VENV_PATH" ]; then
echo "Error: Virtual environment not found at $VENV_PATH"
exit 1
fi
source "$VENV_PATH/bin/activate"
# Launch hypercorn with specified port
hypercorn --bind "0.0.0.0:$PORT" --workers 1 --worker-class asyncio --access-logfile "$ACCESS_LOGFILE" --error-logfile - --log-level info app:app 2>&1 | while IFS= read -r line; do
echo "$line"
if [[ "$line" == *"Address already in use"* ]] || [[ "$line" == *"Errno 98"* ]]; then
echo ""
echo "ERROR: Port $PORT is already in use."
echo "You can change the port using: $0 --port <PORT_NUMBER>"
echo "Example: $0 --port 8080"
exit 1
fi
done
# Capture the exit code from hypercorn
exit ${PIPESTATUS[0]}