From 1b8744fc64f9579e0e307f0aa94174ff59328ed2 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 9 Jun 2021 10:33:57 +0200 Subject: [PATCH] Make runner work on headless server Add runner argument for port --- runner.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/runner.py b/runner.py index 38e2024..f8f38c3 100755 --- a/runner.py +++ b/runner.py @@ -4,28 +4,37 @@ import argparse import subprocess import signal -import bindglobal +try: + import bindglobal + BG = bindglobal.BindGlobal() +except ImportError: + BG = False from expephalon.settings import DEBUG -BG = bindglobal.BindGlobal() - class Expephalon: - def __init__(self, webserver=None, beat=None, worker=None, verbose=None, reload=None): + def __init__(self, webserver=None, beat=None, worker=None, verbose=None, reload=None, bind=None): self.webserver = webserver self.beat = beat self.worker = worker self.verbose = verbose self.reload = reload + self.bind = bind self.webserver_process = None self.beat_process = None self.worker_process = None - def start_webserver(self): + def start_webserver(self, bind=None): if self.verbose: print("Starting Django development webserver") - self.webserver_process = subprocess.Popen("/usr/bin/env python3 manage.py runserver".split()) + + command = "/usr/bin/env python3 manage.py runserver" + + if bind: + command += f" {bind}" + + self.webserver_process = subprocess.Popen(command.split()) def start_beat(self): if self.verbose: @@ -73,16 +82,17 @@ class Expephalon: def start(self): if self.webserver: - self.start_webserver() + self.start_webserver(self.bind) if self.beat != False: self.start_beat() if self.worker != False: self.start_worker() - if self.reload != False: + if BG and self.reload != False: BG.gbind("", self.restart) def stop(self): - BG.gunbind("") + if BG and self.reload != False: + BG.gunbind("") if self.webserver_process: self.stop_webserver() if self.beat_process: @@ -122,7 +132,8 @@ if __name__ == "__main__": parser.add_argument("--no-worker", "-c", action=TRUE, help="Prevent start of Celery worker") parser.add_argument("--verbose", "-v", action=TRUE, help="Print additional information while running") parser.add_argument("--no-reload", "-r", action=TRUE, help="Disable reload on triple-pressing Escape key") + parser.add_argument("--bind", "-B", type=str, help="Local port/IP:Port combination to listen on (default: 127.0.0.1:8000)") args = parser.parse_args() - Expephalon(webserver=False if args.no_webserver or (DEBUG and not args.webserver) else True, beat=not args.no_beat, worker=not args.no_worker, verbose=args.verbose, reload=not args.no_reload).loop() \ No newline at end of file + Expephalon(webserver=False if args.no_webserver or (DEBUG and not args.webserver) else True, beat=not args.no_beat, worker=not args.no_worker, verbose=args.verbose, reload=not args.no_reload, bind=args.bind).loop()