Add run_bjoern script
This commit is contained in:
parent
7d715cc328
commit
81d3272e8a
1 changed files with 44 additions and 0 deletions
44
run_bjoern.py
Executable file
44
run_bjoern.py
Executable file
|
|
@ -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()
|
||||||
Loading…
Add table
Reference in a new issue