pink_fox/services/site/rerun.py
2025-02-27 01:40:30 +03:00

53 lines
2.0 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/python3
import requests
import time
import subprocess
import sys
import os
# Останавливаем контейнер без задержки
subprocess.run(["docker", "compose", "stop", "site", "-t", "0"])
# Устанавливаем переменные окружения в зависимости от передачи аргумента
env = os.environ.copy()
if len(sys.argv) > 1 and sys.argv[1] == "debug":
env["ARG1"] = "debug"
# Запускаем сервис через Docker compose
subprocess.run(["docker", "compose", "up", "site", "-d", "--build"], env=env)
attempt_count = 0
while True:
try:
# Отправляем запрос для проверки поднялся ли HTTP сервер
response = requests.get("http://localhost:12001/ping", timeout=5)
# Проверяем ответ
if response.status_code == 200:
print("Сервер запущен")
break
except requests.ConnectionError:
try:
with open("out.log", 'r') as file:
content = file.read().strip()
if content:
# Лог файл не пуст, возможно, есть ошибки сборки
if content.startswith("API server listening at: [::]:2345"):
# Лог файл начинается с сообщения о старте дебагера, ошибок нет
break
else:
print("Имеется ошибка компиляции, смотри файл out.log")
exit(1)
except FileNotFoundError:
print("Лог файл не найден, проверьте путь")
print("Текущая директория" + os.getcwd())
# Если не удалось подключиться, увеличиваем счетчик попыток
attempt_count += 1
print(f"Ждем... ({attempt_count})")
time.sleep(1)