Enhance logging and error handling in load_prefixes.py and start.sh. The prefix loader now handles file write errors gracefully, while start.sh includes improved permissions setup for log files and named pipes, along with additional checks for ExaBGP process status after startup.
Build and Push Docker Image / build (push) Successful in 3m24s

This commit is contained in:
2025-07-11 17:45:13 +07:00
parent 063c85e4c1
commit ca565b698c
2 changed files with 51 additions and 20 deletions
+13 -6
View File
@@ -24,9 +24,13 @@ def log_message(message: str):
# Вывод в stdout для ExaBGP
print(log_entry, flush=True)
# Запись в файл
with open(LOG_FILE, "a") as f:
f.write(log_entry + "\n")
# Запись в файл (с обработкой ошибок)
try:
with open(LOG_FILE, "a") as f:
f.write(log_entry + "\n")
except (PermissionError, OSError) as e:
# Если не можем записать в файл, просто выводим в stderr
print(f"Warning: Could not write to log file: {e}", file=sys.stderr, flush=True)
def validate_prefix(prefix: str) -> bool:
"""Валидация IP префикса"""
@@ -123,6 +127,12 @@ def withdraw_prefixes(prefixes: Set[str]):
def main():
"""Основная функция"""
# Создание директории для логов в начале
try:
os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
except (PermissionError, OSError):
pass # Игнорируем ошибки создания директории
# Проверка тестового режима
if len(sys.argv) > 1 and sys.argv[1] == '--test':
print("Testing prefix loader...")
@@ -132,9 +142,6 @@ def main():
log_message("Starting prefix loader...")
# Создание директории для логов
os.makedirs(os.path.dirname(LOG_FILE), exist_ok=True)
# Загрузка префиксов
prefixes = load_all_prefixes()
log_message(f"Total prefixes loaded: {len(prefixes)}")