2
2
# =================================================================
3
3
#
4
4
# Authors: Just van den Broecke <[email protected] >
5
+ # Benjamin Webb <[email protected] >
5
6
#
6
7
# Copyright (c) 2019 Just van den Broecke
8
+ # Copyright (c) 2024 Benjamin Webb
7
9
#
8
10
# Permission is hereby granted, free of charge, to any person
9
11
# obtaining a copy of this software and associated documentation
@@ -43,6 +45,7 @@ SCRIPT_NAME=${SCRIPT_NAME:=/}
43
45
CONTAINER_NAME=${CONTAINER_NAME:= pygeoapi}
44
46
CONTAINER_HOST=${CONTAINER_HOST:= 0.0.0.0}
45
47
CONTAINER_PORT=${CONTAINER_PORT:= 80}
48
+ WSGI_APP=${WSGI_APP:= pygeoapi.flask_app: APP}
46
49
WSGI_WORKERS=${WSGI_WORKERS:= 4}
47
50
WSGI_WORKER_TIMEOUT=${WSGI_WORKER_TIMEOUT:= 6000}
48
51
WSGI_WORKER_CLASS=${WSGI_WORKER_CLASS:= gevent}
@@ -66,6 +69,20 @@ pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI}
66
69
67
70
echo " openapi.yml generated continue to pygeoapi"
68
71
72
+ start_gunicorn () {
73
+ # SCRIPT_NAME should not have value '/'
74
+ [[ " ${SCRIPT_NAME} " = ' /' ]] && export SCRIPT_NAME=" " && echo " make SCRIPT_NAME empty from /"
75
+
76
+ echo " Starting gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST} :${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME} "
77
+ exec gunicorn --workers ${WSGI_WORKERS} \
78
+ --worker-class=${WSGI_WORKER_CLASS} \
79
+ --timeout ${WSGI_WORKER_TIMEOUT} \
80
+ --name=${CONTAINER_NAME} \
81
+ --bind ${CONTAINER_HOST} :${CONTAINER_PORT} \
82
+ ${@ } \
83
+ ${WSGI_APP}
84
+ }
85
+
69
86
case ${entry_cmd} in
70
87
# Run Unit tests
71
88
test)
@@ -91,19 +108,21 @@ case ${entry_cmd} in
91
108
92
109
# Run pygeoapi server
93
110
run)
94
- # SCRIPT_NAME should not have value '/'
95
- [[ " ${SCRIPT_NAME} " = ' /' ]] && export SCRIPT_NAME=" " && echo " make SCRIPT_NAME empty from /"
96
-
97
- echo " Start gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST} :${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME} "
98
- exec gunicorn --workers ${WSGI_WORKERS} \
99
- --worker-class=${WSGI_WORKER_CLASS} \
100
- --timeout ${WSGI_WORKER_TIMEOUT} \
101
- --name=${CONTAINER_NAME} \
102
- --bind ${CONTAINER_HOST} :${CONTAINER_PORT} \
103
- pygeoapi.flask_app:APP
104
- ;;
111
+ # Start
112
+ start_gunicorn
113
+ ;;
114
+
115
+ # Run pygeoapi server with hot reload
116
+ run-with-hot-reload)
117
+ # Lock all Python files (for gunicorn hot reload)
118
+ find . -type f -name " *.py" | xargs chmod 0444
119
+
120
+ # Start with hot reload options
121
+ start_gunicorn --reload --reload-extra-file ${PYGEOAPI_CONFIG}
122
+ ;;
123
+
105
124
* )
106
- error " unknown command arg: must be run (default) or test"
125
+ error " unknown command arg: must be run (default), run-with-hot-reload, or test"
107
126
;;
108
127
esac
109
128
0 commit comments