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
31
runner.py
31
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("<Triple-Escape>", self.restart)
|
||||
|
||||
def stop(self):
|
||||
BG.gunbind("<Triple-Escape>")
|
||||
if BG and self.reload != False:
|
||||
BG.gunbind("<Triple-Escape>")
|
||||
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()
|
||||
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