3 Commits

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("--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("-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( parser.add_argument(
"-vv", "-vv",
"--debug", "--debug",
@@ -162,7 +163,9 @@ def main():
app = create_app(config_path=os.path.abspath(args.config_file)) app = create_app(config_path=os.path.abspath(args.config_file))
app.run(debug=args.debug, host=args.host, port=args.port) app.run(debug=args.debug, host=args.host, port=args.port)
else: 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__": if __name__ == "__main__":

View File

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

View File

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