Skip to content

Commit

Permalink
misc: handle BRANCHES_FILE env variable and reload
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Paul Spooren authored and aparcar committed Oct 13, 2022
1 parent 93a2508 commit aa64e18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions asu/asu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions misc/asu.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa64e18

Please sign in to comment.