mirror of
https://github.com/bunkerity/bunkerized-nginx
synced 2023-12-13 21:30:18 +01:00
add ready checks to reversecan and sessions tests
This commit is contained in:
parent
fa628cb7d6
commit
cd773b6e80
|
@ -21,7 +21,7 @@ from pathlib import Path
|
|||
from shutil import copy, rmtree
|
||||
from signal import SIGINT, SIGTERM, signal, SIGHUP
|
||||
from stat import S_IEXEC
|
||||
from subprocess import run as subprocess_run, DEVNULL, STDOUT
|
||||
from subprocess import run as subprocess_run, DEVNULL, STDOUT, PIPE
|
||||
from sys import path as sys_path
|
||||
from tarfile import open as tar_open
|
||||
from threading import Thread
|
||||
|
@ -532,12 +532,13 @@ if __name__ == "__main__":
|
|||
stderr=STDOUT,
|
||||
env=env.copy(),
|
||||
check=False,
|
||||
stdout=PIPE
|
||||
)
|
||||
if proc.returncode == 0:
|
||||
logger.info("Successfully sent reload signal to nginx")
|
||||
else:
|
||||
logger.error(
|
||||
f"Error while reloading nginx - returncode: {proc.returncode} - error: {proc.stderr.decode('utf-8') if proc.stderr else 'Missing stderr'}",
|
||||
f"Error while reloading nginx - returncode: {proc.returncode} - error: {proc.stdout.decode('utf-8') if proc.stdout else 'no output'}",
|
||||
)
|
||||
# # Stop temp nginx
|
||||
# logger.info("Stopping temp nginx ...")
|
||||
|
|
|
@ -179,6 +179,8 @@ try:
|
|||
global_values = session.query(Global_values).all()
|
||||
|
||||
for global_value in global_values:
|
||||
if global_value.setting_id == "API_LISTEN_IP":
|
||||
continue
|
||||
if global_value.setting_id in global_settings:
|
||||
if global_value.value != global_settings[global_value.setting_id]["value"]:
|
||||
print(
|
||||
|
|
|
@ -6,6 +6,8 @@ from requests import get
|
|||
from multiprocessing import Process
|
||||
from traceback import format_exc
|
||||
from uvicorn import run
|
||||
from contextlib import suppress
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
|
||||
fastapi_proc = None
|
||||
|
@ -17,6 +19,28 @@ if getenv("TEST_TYPE", "docker") == "docker":
|
|||
sleep(1)
|
||||
|
||||
try:
|
||||
ready = False
|
||||
retries = 0
|
||||
while not ready:
|
||||
with suppress(RequestException):
|
||||
resp = get("http://www.example.com/ready", headers={"Host": "www.example.com"})
|
||||
status_code = resp.status_code
|
||||
text = resp.text
|
||||
|
||||
if status_code >= 500:
|
||||
print("❌ An error occurred with the server, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
ready = status_code < 400 or status_code == 403 and text == "ready"
|
||||
|
||||
if retries > 10:
|
||||
print("❌ The service took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
elif not ready:
|
||||
retries += 1
|
||||
print("⚠️ Waiting for the service to be ready, retrying in 5s ...", flush=True)
|
||||
sleep(5)
|
||||
|
||||
use_reverse_scan = getenv("USE_REVERSE_SCAN", "yes") == "yes"
|
||||
reverse_scan_ports = getenv("REVERSE_SCAN_PORTS", "80")
|
||||
|
||||
|
|
|
@ -13,13 +13,15 @@ try:
|
|||
retries = 0
|
||||
while not ready:
|
||||
with suppress(RequestException):
|
||||
status_code = get("http://www.example.com", headers={"Host": "www.example.com"}).status_code
|
||||
resp = get("http://www.example.com/ready", headers={"Host": "www.example.com"})
|
||||
status_code = resp.status_code
|
||||
text = resp.text
|
||||
|
||||
if status_code >= 500:
|
||||
print("❌ An error occurred with the server, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
ready = status_code < 400
|
||||
ready = status_code < 400 and text == "ready"
|
||||
|
||||
if retries > 10:
|
||||
print("❌ The service took too long to be ready, exiting ...", flush=True)
|
||||
|
@ -76,22 +78,27 @@ try:
|
|||
print("❌ An error occurred when restarting BunkerWeb, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
ready = False
|
||||
retries = 0
|
||||
while (
|
||||
b"BunkerWeb is ready"
|
||||
not in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("ℹ️ Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
while not ready:
|
||||
with suppress(RequestException):
|
||||
resp = get("http://www.example.com/ready", headers={"Host": "www.example.com"})
|
||||
status_code = resp.status_code
|
||||
text = resp.text
|
||||
|
||||
if retries >= 10:
|
||||
if status_code >= 500:
|
||||
print("❌ An error occurred with the server, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
ready = status_code < 400 and text == "ready"
|
||||
|
||||
if retries > 10:
|
||||
print("❌ BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
elif not ready:
|
||||
retries += 1
|
||||
print("⚠️ Waiting for BunkerWeb to be ready, retrying in 5s ...", flush=True)
|
||||
sleep(5)
|
||||
|
||||
print("ℹ️ Starting Firefox again ...", flush=True)
|
||||
with webdriver.Firefox(options=firefox_options) as driver:
|
||||
|
|
Loading…
Reference in a new issue