Make runner work on headless server
Add runner argument for port
This commit is contained in:
parent
86cabdc77d
commit
1b8744fc64
1 changed files with 21 additions and 10 deletions
27
runner.py
27
runner.py
|
@ -4,28 +4,37 @@ import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
|
try:
|
||||||
import bindglobal
|
import bindglobal
|
||||||
|
BG = bindglobal.BindGlobal()
|
||||||
|
except ImportError:
|
||||||
|
BG = False
|
||||||
|
|
||||||
from expephalon.settings import DEBUG
|
from expephalon.settings import DEBUG
|
||||||
|
|
||||||
BG = bindglobal.BindGlobal()
|
|
||||||
|
|
||||||
class Expephalon:
|
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.webserver = webserver
|
||||||
self.beat = beat
|
self.beat = beat
|
||||||
self.worker = worker
|
self.worker = worker
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.reload = reload
|
self.reload = reload
|
||||||
|
self.bind = bind
|
||||||
|
|
||||||
self.webserver_process = None
|
self.webserver_process = None
|
||||||
self.beat_process = None
|
self.beat_process = None
|
||||||
self.worker_process = None
|
self.worker_process = None
|
||||||
|
|
||||||
def start_webserver(self):
|
def start_webserver(self, bind=None):
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("Starting Django development webserver")
|
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):
|
def start_beat(self):
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
|
@ -73,15 +82,16 @@ class Expephalon:
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.webserver:
|
if self.webserver:
|
||||||
self.start_webserver()
|
self.start_webserver(self.bind)
|
||||||
if self.beat != False:
|
if self.beat != False:
|
||||||
self.start_beat()
|
self.start_beat()
|
||||||
if self.worker != False:
|
if self.worker != False:
|
||||||
self.start_worker()
|
self.start_worker()
|
||||||
if self.reload != False:
|
if BG and self.reload != False:
|
||||||
BG.gbind("<Triple-Escape>", self.restart)
|
BG.gbind("<Triple-Escape>", self.restart)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
if BG and self.reload != False:
|
||||||
BG.gunbind("<Triple-Escape>")
|
BG.gunbind("<Triple-Escape>")
|
||||||
if self.webserver_process:
|
if self.webserver_process:
|
||||||
self.stop_webserver()
|
self.stop_webserver()
|
||||||
|
@ -122,7 +132,8 @@ if __name__ == "__main__":
|
||||||
parser.add_argument("--no-worker", "-c", action=TRUE, help="Prevent start of Celery worker")
|
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("--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("--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()
|
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()
|
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()
|
||||||
|
|
Loading…
Reference in a new issue