From aa64e18f4551beb768df39a386771c966a18755a Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Thu, 13 Oct 2022 09:37:19 +0200 Subject: [PATCH] misc: handle BRANCHES_FILE env variable and reload if the BRANCHES_FILE is set i.e. via service file automatically reload gunicorn. This allows the modification of branches.yml without restarting the service manually. Signed-off-by: Paul Spooren --- asu/asu.py | 5 +++-- misc/asu.service | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/asu/asu.py b/asu/asu.py index 4b5f0a15..a9c6c39d 100644 --- a/asu/asu.py +++ b/asu/asu.py @@ -38,6 +38,7 @@ def create_app(test_config: dict = None) -> Flask: UPSTREAM_URL="https://downloads.openwrt.org", ALLOW_DEFAULTS=False, ASYNC_QUEUE=True, + BRANCHES_FILE=getenv("BRANCHES_FILE"), ) if not test_config: @@ -58,8 +59,8 @@ def create_app(test_config: dict = None) -> Flask: app.config[option] = Path(value) app.config[option].mkdir(parents=True, exist_ok=True) - if not "BRANCHES" in app.config: - if "BRANCHES_FILE" not in app.config: + if "BRANCHES" not in app.config: + if app.config["BRANCHES_FILE"] is None: app.config["BRANCHES_FILE"] = resource_filename(__name__, "branches.yml") with open(app.config["BRANCHES_FILE"], "r") as branches: diff --git a/misc/asu.service b/misc/asu.service index 98d41789..8b915ff7 100644 --- a/misc/asu.service +++ b/misc/asu.service @@ -6,8 +6,14 @@ After=network.target User=debian Group=debian WorkingDirectory=/home/debian/asu/ -Environment="PATH=/home/debian/.local/bin/" -ExecStart=/home/debian/.local/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 -m 007 "asu.asu:create_app()" +Environment="BRANCHES_FILE=./branches.yml" +ExecStart=/home/debian/.local/bin/gunicorn \ + --bind 127.0.0.1:8000 \ + --extra-reload-file "$BRANCHES_FILE" \ + --reload \ + --umask 007 \ + --workers 3 \ + "asu.asu:create_app()" [Install] WantedBy=multi-user.target