commit
83b851000f
1 changed files with 3 additions and 36 deletions
|
@ -12,7 +12,6 @@ from sys import stdout
|
|||
from sys import stderr
|
||||
|
||||
|
||||
|
||||
# some vars
|
||||
devel = False
|
||||
caddy_process = None
|
||||
|
@ -20,70 +19,48 @@ scs_process = None
|
|||
app_process = None
|
||||
|
||||
|
||||
|
||||
def stop():
|
||||
|
||||
print("\n\nStopping services.\n\n")
|
||||
|
||||
caddy_process.send_signal(SIGINT)
|
||||
scs_process.send_signal(SIGINT)
|
||||
app_process.send_signal(SIGINT)
|
||||
|
||||
print(f"Caddy stopped with exit code {caddy_process.wait()}.")
|
||||
|
||||
print(f"session-clear-scheduler stopped with exit code {scs_process.wait()}.")
|
||||
|
||||
if devel:
|
||||
print(f"Django stopped with exit code {app_process.wait()}.")
|
||||
else:
|
||||
print(f"Django/Uvicorn stopped with exit code {app_process.wait()}.")
|
||||
|
||||
if caddy_process.returncode != 0 or scs_process.returncode != 0 or app_process.returncode !=0:
|
||||
exit(1)
|
||||
else:
|
||||
exit(0)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# development or production environment?
|
||||
try:
|
||||
if argv[1] == "devel":
|
||||
devel = True
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
# vars
|
||||
|
||||
pwd = getcwd()
|
||||
|
||||
APPLICATION_LOG = environ["APPLICATION_LOG"]
|
||||
CADDY_ACCESS_LOG = environ["CADDY_ACCESS_LOG"]
|
||||
CADDY_LOG = environ["CADDY_LOG"]
|
||||
|
||||
DJANGO_PORT = environ["DJANGO_PORT"]
|
||||
HTTPS_PORT = environ["HTTPS_PORT"]
|
||||
|
||||
if devel:
|
||||
environ["DJANGO_DEBUG"] = "true"
|
||||
else:
|
||||
environ["DJANGO_DEBUG"] = "false"
|
||||
|
||||
|
||||
# info
|
||||
|
||||
print(f"\n\nStarting server on port {HTTPS_PORT}...\nYou should be able to access the application locally at https://localhost:{HTTPS_PORT}/\n\nPress Ctrl+C to stop all services.\n\n")
|
||||
print(f"\n\nStarting server on port {HTTPS_PORT}...\nYou should be able to access the application locally at https://127.0.0.1:{HTTPS_PORT}/\n\nPress Ctrl+C to stop all services.\n\n")
|
||||
if not devel:
|
||||
print(f"All further messages will be written to {APPLICATION_LOG} and {CADDY_LOG}")
|
||||
print(f"HTTP Access Log will be written to {CADDY_ACCESS_LOG}")
|
||||
|
||||
|
||||
try:
|
||||
|
||||
# start django/uvicorn
|
||||
|
||||
if devel:
|
||||
run(
|
||||
["python3", f"{pwd}/application/manage.py", "collectstatic", "--noinput"],
|
||||
|
@ -92,7 +69,7 @@ if __name__ == "__main__":
|
|||
env=environ
|
||||
)
|
||||
app_process = Popen(
|
||||
["python3", f"{pwd}/application/manage.py", "runserver", f"localhost:{DJANGO_PORT}"],
|
||||
["python3", f"{pwd}/application/manage.py", "runserver", f"127.0.0.1:{DJANGO_PORT}"],
|
||||
stdout=stdout,
|
||||
stderr=stderr,
|
||||
env=environ
|
||||
|
@ -108,7 +85,7 @@ if __name__ == "__main__":
|
|||
app_process = Popen(
|
||||
[
|
||||
"python3", "-m", "uvicorn",
|
||||
"--host", "localhost",
|
||||
"--host", "127.0.0.1",
|
||||
"--port", quote(DJANGO_PORT),
|
||||
"drinks_manager.asgi:application"
|
||||
],
|
||||
|
@ -117,41 +94,31 @@ if __name__ == "__main__":
|
|||
cwd=f"{pwd}/application/",
|
||||
env=environ
|
||||
)
|
||||
|
||||
# start caddy
|
||||
|
||||
if devel:
|
||||
caddy_log_file = stdout
|
||||
caddy_log_file_stderr = stderr
|
||||
else:
|
||||
caddy_log_file = caddy_log_file_stderr = open(CADDY_LOG, "a")
|
||||
|
||||
caddy_process = Popen(
|
||||
["caddy", "run", "--config", f"{pwd}/config/Caddyfile"],
|
||||
stdout=caddy_log_file,
|
||||
stderr=caddy_log_file_stderr,
|
||||
env=environ
|
||||
)
|
||||
|
||||
# start session-clear-scheduler
|
||||
|
||||
if devel:
|
||||
clear_sched_log_file = stdout
|
||||
clear_sched_log_file_stderr = stderr
|
||||
else:
|
||||
clear_sched_log_file = clear_sched_log_file_stderr = open(APPLICATION_LOG, "a")
|
||||
|
||||
scs_process = Popen(
|
||||
["python3", f"{pwd}/lib/session-clear-scheduler.py"],
|
||||
stdout=clear_sched_log_file,
|
||||
stderr=clear_sched_log_file_stderr
|
||||
)
|
||||
|
||||
caddy_process.wait()
|
||||
scs_process.wait()
|
||||
app_process.wait()
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
|
||||
stop()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue