Do a bit of refactoring in the bootstrap script
This commit is contained in:
parent
267ce0188a
commit
3f0a0d79d0
1 changed files with 124 additions and 115 deletions
|
@ -12,43 +12,75 @@ from sys import stdout
|
||||||
from sys import stderr
|
from sys import stderr
|
||||||
|
|
||||||
|
|
||||||
# devel or prod?
|
|
||||||
|
|
||||||
|
# some vars
|
||||||
devel = False
|
devel = False
|
||||||
|
caddy_process = None
|
||||||
|
scs_process = None
|
||||||
|
app_process = None
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
|
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":
|
if argv[1] == "devel":
|
||||||
devel = True
|
devel = True
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# vars
|
# vars
|
||||||
|
|
||||||
pwd = getcwd()
|
pwd = getcwd()
|
||||||
|
|
||||||
APPLICATION_LOG = environ["APPLICATION_LOG"]
|
APPLICATION_LOG = environ["APPLICATION_LOG"]
|
||||||
CADDY_ACCESS_LOG = environ["CADDY_ACCESS_LOG"]
|
CADDY_ACCESS_LOG = environ["CADDY_ACCESS_LOG"]
|
||||||
CADDY_LOG = environ["CADDY_LOG"]
|
CADDY_LOG = environ["CADDY_LOG"]
|
||||||
|
|
||||||
DJANGO_PORT = environ["DJANGO_PORT"]
|
DJANGO_PORT = environ["DJANGO_PORT"]
|
||||||
HTTPS_PORT = environ["HTTPS_PORT"]
|
HTTPS_PORT = environ["HTTPS_PORT"]
|
||||||
|
|
||||||
if devel:
|
if devel:
|
||||||
environ["DJANGO_DEBUG"] = "true"
|
environ["DJANGO_DEBUG"] = "true"
|
||||||
else:
|
else:
|
||||||
environ["DJANGO_DEBUG"] = "false"
|
environ["DJANGO_DEBUG"] = "false"
|
||||||
|
|
||||||
|
|
||||||
# info
|
# 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://localhost:{HTTPS_PORT}/\n\nPress Ctrl+C to stop all services.\n\n")
|
||||||
if not devel:
|
if not devel:
|
||||||
print(f"All further messages will be written to {APPLICATION_LOG} and {CADDY_LOG}")
|
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}")
|
print(f"HTTP Access Log will be written to {CADDY_ACCESS_LOG}")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
# start django/uvicorn
|
# start django/uvicorn
|
||||||
|
|
||||||
|
@ -120,29 +152,6 @@ try:
|
||||||
app_process.wait()
|
app_process.wait()
|
||||||
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
||||||
# exit
|
stop()
|
||||||
|
|
||||||
print("\n\nStopping services.\n\n")
|
|
||||||
|
|
||||||
caddy_process.send_signal(SIGINT)
|
|
||||||
scs_process.send_signal(SIGINT)
|
|
||||||
app_process.send_signal(SIGINT)
|
|
||||||
|
|
||||||
caddy_process.wait()
|
|
||||||
print(f"Caddy stopped with exit code {caddy_process.returncode}.")
|
|
||||||
|
|
||||||
scs_process.wait()
|
|
||||||
print(f"session-clear-scheduler stopped with exit code {scs_process.returncode}.")
|
|
||||||
|
|
||||||
app_process.wait()
|
|
||||||
if devel:
|
|
||||||
print(f"Django stopped with exit code {app_process.returncode}.")
|
|
||||||
else:
|
|
||||||
print(f"Django/Uvicorn stopped with exit code {app_process.returncode}.")
|
|
||||||
|
|
||||||
if caddy_process.returncode != 0 or scs_process.returncode != 0 or app_process.returncode !=0:
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
exit(0)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue