22# =================================================================
33#
44# Authors: Just van den Broecke <[email protected] >5+ # Benjamin Webb <[email protected] >56#
67# Copyright (c) 2019 Just van den Broecke
8+ # Copyright (c) 2024 Benjamin Webb
79#
810# Permission is hereby granted, free of charge, to any person
911# obtaining a copy of this software and associated documentation
@@ -43,6 +45,7 @@ SCRIPT_NAME=${SCRIPT_NAME:=/}
4345CONTAINER_NAME=${CONTAINER_NAME:= pygeoapi}
4446CONTAINER_HOST=${CONTAINER_HOST:= 0.0.0.0}
4547CONTAINER_PORT=${CONTAINER_PORT:= 80}
48+ WSGI_APP=${WSGI_APP:= pygeoapi.flask_app: APP}
4649WSGI_WORKERS=${WSGI_WORKERS:= 4}
4750WSGI_WORKER_TIMEOUT=${WSGI_WORKER_TIMEOUT:= 6000}
4851WSGI_WORKER_CLASS=${WSGI_WORKER_CLASS:= gevent}
@@ -66,6 +69,20 @@ pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI}
6669
6770echo " openapi.yml generated continue to pygeoapi"
6871
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+
6986case ${entry_cmd} in
7087 # Run Unit tests
7188 test)
@@ -91,19 +108,21 @@ case ${entry_cmd} in
91108
92109 # Run pygeoapi server
93110 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+
105124 * )
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"
107126 ;;
108127esac
109128
0 commit comments