-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup.sh
More file actions
executable file
·47 lines (38 loc) · 1.02 KB
/
startup.sh
File metadata and controls
executable file
·47 lines (38 loc) · 1.02 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
#!/usr/bin/env sh
# shellcheck disable=SC1091,SC2034,SC2086,SC2153,SC2236,SC3037,SC3045,SC2046
if [ "$(uname -s)" = "Darwin" ]; then
export VENV=".venv"
else
export VENV="/opt/venv"
fi
export PATH="${VENV}/bin:$HOME/.asdf/bin:$HOME/.asdf/shims:$PATH"
# . "${VENV}/bin/activate"
BASE_DIR="$(dirname "$(readlink -f "$0")")"
move_port() {
echo "Port $1 is in use, trying $PORT"
while [ ! -z "$(lsof -i :$PORT | grep LISTEN | awk '{print $2}')" ]; do
echo "Port $PORT is in use, trying $((PORT+1))"
PORT=$((PORT+1))
done
echo "Port $PORT is available. Using it instead of $1"
}
port_check() {
if [ -z "$1" ]; then
PORT=3000
elif [ "$1" -gt 0 ] 2>/dev/null; then
PORT="$1"
fi
[ -z "$(lsof -i :$PORT | grep LISTEN | awk '{print $2}')" ] || move_port "$PORT"
}
server() {
# gunicorn/uvicorn
gunicorn -w 2 -k uvicorn.workers.UvicornWorker main:app -b "0.0.0.0:${PORT}" --log-file -
# django
# SRV_DIR="${BASE_DIR}/app/commerce"
# python "${SRV_DIR}/manage.py" runserver
}
main() {
port_check "$@"
server
}
main "$@"