From d008efad8ef7270fe8553006640cf1e447f9421e Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Mon, 3 May 2021 12:12:42 +0200 Subject: [PATCH] Align with running engine. engine#72 --- README.md | 12 +++++++----- run.sh | 27 ++++++++++++++------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a27b2df..7f5b6f8 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ The *Engine API syncronization node* always only stores the valid (i.e. actually This top-down synchronization process of posting any incoming playlogs at the *Engine Node* also to the *Synchronization Node* can be called **Active Sync**. This **Active Sync** doesn't work in every scenario, as there might be the case, that the *Synchronization Node* is not available e.g. due to network outage, maintenance etc. In this situation the playlog -obviously can not be synced. That means the local playlog at the *Engine Node* is marked as "not synced". +obviously can not be synced. That means the local playlog at the *Engine Node* is marked as "not synced". ##### Passive Sync @@ -213,9 +213,11 @@ sync_step_sleep=2 To run the API in an local development server execute: ```bash -./run.sh api-dev +./run.sh dev ``` +This command implicitely activates the virtual environment before starting the API. + For convenience running a plain `./run.sh` also starts the development server. In development mode Engine uses the default [Flask](https://palletsprojects.com/p/flask/) web server. @@ -238,9 +240,9 @@ For production Engine API defaults to using the WSGI HTTP Server [`Gunicorn`](ht You might also want to pair Gunicorn with some proxy server, such as Nginx. -> Although there are many HTTP proxies available, we strongly advise that you use Nginx. If you choose another proxy -server you need to make sure that it buffers slow clients when you use default Gunicorn workers. Without this buffering -Gunicorn will be easily susceptible to denial-of-service attacks. You can use Hey to check if your proxy is behaving properly. +> Although there are many HTTP proxies available, we strongly advise that you use Nginx. If you choose another proxy +server you need to make sure that it buffers slow clients when you use default Gunicorn workers. Without this buffering +Gunicorn will be easily susceptible to denial-of-service attacks. You can use Hey to check if your proxy is behaving properly. — [**Gunicorn Docs**](http://docs.gunicorn.org/en/latest/deploy.html). To run Gunicorn, you first need to create the Gunicorn configuration diff --git a/run.sh b/run.sh index 397178b..c367cde 100755 --- a/run.sh +++ b/run.sh @@ -1,6 +1,6 @@ #!/bin/bash # Default mode -mode="api-dev" +mode="dev" docker="false" # @@ -8,7 +8,7 @@ docker="false" # # Call with one of these parameters: # -# - api-dev +# - dev # - api # - test # - recreate-database @@ -17,10 +17,10 @@ docker="false" # - docker:build # - docker:push # - docker:api -# +# -if [[ $* =~ ^(api-dev|api-test-0|api-test-1|api-test-2|api|test)$ ]]; then - mode=$1 +if [[ $* =~ ^(dev|api-test-0|api-test-1|api-test-2|api|test)$ ]]; then + mode=$1 fi if [[ "$1" == *"docker:"* ]]; then @@ -32,6 +32,9 @@ fi echo "[ Run mode=$mode ]" echo "[ Docker=$docker ]" +# Check for the correct Python version (3.8+) +PYTHON_EXEC="python3" +echo "[ Using $(python3 -V) ]" # +++ DEFAULT COMMANDS +++ # @@ -40,9 +43,9 @@ if [[ $docker == "false" ]]; then ### Runs the API Server (Development) ### - if [[ $mode == "api-dev" ]]; then - echo "Activating Python Environment" - source python/bin/activate + if [[ $mode == "dev" ]]; then + source python/bin/activate + echo "Running Engine API in Python Environment ($(python3 -V))" echo "Starting API Server" python src/app.py fi @@ -51,22 +54,20 @@ if [[ $docker == "false" ]]; then if [[ $mode == "api-test-0" ]]; then echo "Starting API Server 0" - /usr/bin/env python3 src/app.py config=tests/config/engine-0-api.ini + /usr/bin/env python3 src/app.py config=tests/config/engine-0-api.ini fi if [[ $mode == "api-test-1" ]]; then echo "Starting API Server 1" - /usr/bin/env python3 src/app.py config=tests/config/engine-1-api.ini + /usr/bin/env python3 src/app.py config=tests/config/engine-1-api.ini fi if [[ $mode == "api-test-2" ]]; then echo "Starting API Server 2" - /usr/bin/env python3 src/app.py config=tests/config/engine-2-api.ini + /usr/bin/env python3 src/app.py config=tests/config/engine-2-api.ini fi ### Runs the API Server using Gunicorn without a system daemon (Production) ### if [[ $mode == "api" ]]; then - echo "Activating Python Environment" - source python/bin/activate echo "Starting API Server" gunicorn -c config/gunicorn.conf.py src.app:app fi -- GitLab