feat: live update log in UI and suppress lifecycle Telegram during SAC update
Poll remote update_script.log while SSH update runs; skip lifecycle notify when host agent_update_state is running (SAC v0.5.1).
This commit is contained in:
@@ -9,6 +9,7 @@ from dataclasses import dataclass
|
||||
from app.config import get_settings
|
||||
from app.models import Host
|
||||
|
||||
SSH_MONITOR_UPDATE_LOG_PATH = "/var/log/update_script.log"
|
||||
SSH_MONITOR_UPDATE_SCRIPT = "/opt/scripts/update_ssh_monitor.sh"
|
||||
SSH_MONITOR_UPDATE_DIR = "/opt/scripts/update"
|
||||
SSH_MONITOR_REPO_NAME = "ssh-monitor"
|
||||
@@ -549,3 +550,29 @@ def run_ssh_monitor_update(
|
||||
exit_code=updated.exit_code,
|
||||
)
|
||||
return updated
|
||||
|
||||
|
||||
def tail_ssh_monitor_update_log(
|
||||
*,
|
||||
target: str,
|
||||
user: str,
|
||||
password: str,
|
||||
lines: int = 120,
|
||||
) -> str:
|
||||
"""Хвост /var/log/update_script.log на удалённом хосте (для live-лога в SAC UI)."""
|
||||
safe_lines = max(20, min(int(lines), 400))
|
||||
remote_cmd = (
|
||||
f"test -r {SSH_MONITOR_UPDATE_LOG_PATH} && "
|
||||
f"tail -n {safe_lines} {SSH_MONITOR_UPDATE_LOG_PATH} 2>/dev/null || true"
|
||||
)
|
||||
result = run_ssh_command(
|
||||
target=target,
|
||||
user=user,
|
||||
password=password,
|
||||
remote_cmd=remote_cmd,
|
||||
command_timeout_sec=25,
|
||||
need_root=True,
|
||||
login_shell=False,
|
||||
)
|
||||
text = (result.stdout or "").strip()
|
||||
return _truncate_output(text)
|
||||
|
||||
Reference in New Issue
Block a user