diff --git a/run_bjoern.py b/run_bjoern.py new file mode 100755 index 0000000..0f70717 --- /dev/null +++ b/run_bjoern.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import bjoern +import os +import socket +import traceback + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'conf.settings.production') +app = get_wsgi_application() + +NUM_WORKERS = 1 +worker_pids = [] + +socket_path = "/var/run/reinheit/reinheit.sock" + +try: + os.unlink(socket_path) +except OSError: + if os.path.exists(socket_path): + os.remove(socket_path) + +sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +sock.bind(socket_path) +sock.listen() + +print("Setting access mode to 777") +os.chmod(socket_path, 0o777) + + +try: + print(f"Serving reinheit via {socket_path}") + bjoern.server_run(sock, app) +except Exception: + traceback.print_exc() + try: + sock.close() + except Exception: + traceback.print_exc() + try: + os.remove(socket_path) + except Exception: + traceback.print_exc()