fix: improve docker logs retrieval and diagnostics
- Updated cmd_logs to combine stdout and stderr streams. - Added a check for container existence before fetching logs. - Increased log tail limit to 50 lines. - Improved user feedback when logs are empty but the container is running.
This commit is contained in:
22
install.sh
22
install.sh
@@ -331,11 +331,25 @@ async def cmd_restart(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
|
|
||||||
async def cmd_logs(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
async def cmd_logs(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
if not update.effective_user or not _ok(update.effective_user.id): return
|
if not update.effective_user or not _ok(update.effective_user.id): return
|
||||||
code, out, err = await sh("docker", "logs", "--tail", "30", CONTAINER_NAME, timeout=15)
|
|
||||||
text = f"<pre>{html.escape(out or err or 'Логов нет.')}</pre>"
|
running = await proxy_running()
|
||||||
|
if not running:
|
||||||
|
text = "❌ <b>Контейнер не найден или остановлен.</b>"
|
||||||
|
else:
|
||||||
|
# Запрашиваем 50 строк и объединяем выводы
|
||||||
|
code, out, err = await sh("docker", "logs", "--tail", "50", CONTAINER_NAME, timeout=15)
|
||||||
|
combined_logs = (out.strip() + "\n" + err.strip()).strip()
|
||||||
|
|
||||||
|
if not combined_logs:
|
||||||
|
text = "📋 <b>Контейнер запущен, но логи пока пусты.</b>\n<i>Попробуйте подключиться к прокси, чтобы появились записи.</i>"
|
||||||
|
else:
|
||||||
|
text = f"<pre>{html.escape(combined_logs)}</pre>"
|
||||||
|
|
||||||
kb = InlineKeyboardMarkup([[InlineKeyboardButton("◀️ Меню", callback_data="menu_main")]])
|
kb = InlineKeyboardMarkup([[InlineKeyboardButton("◀️ Меню", callback_data="menu_main")]])
|
||||||
if update.callback_query: await update.callback_query.edit_message_text(text, parse_mode="HTML", reply_markup=kb)
|
if update.callback_query:
|
||||||
else: await update.message.reply_text(text, parse_mode="HTML", reply_markup=kb)
|
await update.callback_query.edit_message_text(text, parse_mode="HTML", reply_markup=kb)
|
||||||
|
else:
|
||||||
|
await update.message.reply_text(text, parse_mode="HTML", reply_markup=kb)
|
||||||
|
|
||||||
async def do_install(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
async def do_install(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
domain = ctx.user_data.get("install_domain", "google.com")
|
domain = ctx.user_data.get("install_domain", "google.com")
|
||||||
|
|||||||
Reference in New Issue
Block a user