3 Commits
v0.1.1 ... main

Author SHA1 Message Date
92afde02a5 Bump version: 0.1.1 → 0.1.2
Some checks failed
Test suites / test-os-python-matrix (ubuntu-22.04, 3.10) (push) Failing after 1m49s
Test suites / test-os-python-matrix (ubuntu-22.04, 3.12) (push) Failing after 1m49s
Test suites / test-os-python-matrix (ubuntu-22.04, 3.13) (push) Failing after 1m48s
Test suites / test-os-python-matrix (ubuntu-22.04, 3.11) (push) Failing after 2m10s
Test suites / test-build-install (push) Failing after 29s
Test suites / pylint (push) Failing after 28s
Test suites / formatting (push) Failing after 28s
Test suites / reuse (push) Successful in 41s
Test suites / mypy (push) Failing after 49s
Test suites / test-os-python-matrix (macos-latest, 3.10) (push) Has been cancelled
Test suites / test-os-python-matrix (windows-latest, 3.10) (push) Has been cancelled
2025-04-01 22:35:44 +02:00
Max Mehl
c3e53ddb94 Merge pull request #2 from mxmehl/fix-gunicorn
Use gunicorn programmatically
2025-04-01 22:35:26 +02:00
73d1a51838 feat: use gunicorn programmatically, make configurable 2025-04-01 22:34:21 +02:00
3 changed files with 18 additions and 16 deletions

View File

@@ -148,6 +148,7 @@ def main():
)
parser.add_argument("--host", default="localhost", help="Hostname of the server")
parser.add_argument("-p", "--port", type=int, default=8000, help="Port of the server")
parser.add_argument("-w", "--workers", type=int, default=4, help="Gunicorn webserver workers")
parser.add_argument(
"-vv",
"--debug",
@@ -162,7 +163,9 @@ def main():
app = create_app(config_path=os.path.abspath(args.config_file))
app.run(debug=args.debug, host=args.host, port=args.port)
else:
serve_via_gunicorn(config_file=args.config_file)
serve_via_gunicorn(
config_file=args.config_file, host=args.host, port=args.port, workers=args.workers
)
if __name__ == "__main__":

View File

@@ -7,11 +7,12 @@
import hashlib
import hmac
import os
import subprocess
import sys
import yaml
from bcrypt import checkpw
from flask import Flask, abort, current_app, request
from gunicorn.app.wsgiapp import WSGIApplication
def load_config(app: Flask, filename: str) -> None:
@@ -71,16 +72,14 @@ def get_stream_token(username: str) -> str:
return hmac.new(secret.encode(), username.encode(), hashlib.sha256).hexdigest()[:16]
def serve_via_gunicorn(config_file: str) -> None:
"""Serve the application using Gunicorn."""
subprocess.run(
[
"gunicorn",
"-w",
"4",
"-b",
"0.0.0.0:8000",
f"home_stream.wsgi:create_app('{config_file}')",
],
check=True,
)
def serve_via_gunicorn(config_file: str, host: str, port: int, workers: int) -> None:
"""Serve the application using Gunicorn programmatically."""
sys.argv = [
"gunicorn",
"-w",
str(workers),
"-b",
f"{host}:{port}",
f"home_stream.wsgi:create_app('{config_file}')",
]
WSGIApplication().run()

View File

@@ -4,7 +4,7 @@
[tool.poetry]
name = "home-stream"
version = "0.1.1"
version = "0.1.2"
description = "Browser and streaming interface for local media files"
repository = "https://github.com/mxmehl/home-stream"
authors = ["Max Mehl <mail@mehl.mx>"]