From b839de20503189eea85b3f20c76b26831fe2db97 Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Wed, 18 Mar 2026 12:56:05 +0800 Subject: [PATCH] fix(discord): handle timeout error on shutdown; chore(cli): remove systemd service creation --- astrbot/cli/commands/cmd_init.py | 50 ------------------- .../discord/discord_platform_adapter.py | 2 + 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/astrbot/cli/commands/cmd_init.py b/astrbot/cli/commands/cmd_init.py index d1ab060a3..b60e109f0 100644 --- a/astrbot/cli/commands/cmd_init.py +++ b/astrbot/cli/commands/cmd_init.py @@ -1,7 +1,4 @@ import asyncio -import platform -import shutil -import subprocess from pathlib import Path import click @@ -11,29 +8,6 @@ from astrbot.core.utils.astrbot_path import astrbot_paths from ..utils import check_dashboard -SYSTEMD_SERVICE = r""" -# user service -[Unit] -Description=AstrBot Service -Documentation=https://github.com/AstrBotDevs/AstrBot -After=network-online.target -Wants=network-online.target - -[Service] -Type=simple -WorkingDirectory=%h/.local/share/astrbot -ExecStart=/usr/bin/sh -c '/usr/bin/astrbot run || { /usr/bin/astrbot init && /usr/bin/astrbot run; }' -Restart=on-failure -RestartSec=5 -StandardOutput=journal -StandardError=journal -SyslogIdentifier=astrbot-%u -Environment=PYTHONUNBUFFERED=1 - -[Install] -WantedBy=default.target -""" - async def initialize_astrbot( astrbot_root: Path, *, yes: bool, backend_only: bool @@ -82,30 +56,6 @@ def init(yes: bool, backend_only: bool) -> None: """Initialize AstrBot""" click.echo("Initializing AstrBot...") - # 检查当前系统是否为 Linux 且存在 systemd - if platform.system() == "Linux" and shutil.which("systemctl"): - if yes or click.confirm( - "Detected Linux with systemd. Install AstrBot user service?", default=True - ): - user_config_dir = Path.home() / ".config" / "systemd" / "user" - user_config_dir.mkdir(parents=True, exist_ok=True) - - service_path = user_config_dir / "astrbot.service" - - service_path.write_text(SYSTEMD_SERVICE) - click.echo(f"Created service file at {service_path}") - - try: - subprocess.run(["systemctl", "--user", "daemon-reload"], check=True) - click.echo("Systemd daemon reloaded.") - click.echo("Management commands:") - click.echo(" Start: systemctl --user start astrbot") - click.echo(" Stop: systemctl --user stop astrbot") - click.echo(" Enable: systemctl --user enable astrbot") - click.echo(" Log: journalctl --user -u astrbot -f") - except subprocess.CalledProcessError as e: - click.echo(f"Failed to reload systemd daemon: {e}", err=True) - astrbot_root = astrbot_paths.root lock_file = astrbot_root / "astrbot.lock" lock = FileLock(lock_file, timeout=5) diff --git a/astrbot/core/platform/sources/discord/discord_platform_adapter.py b/astrbot/core/platform/sources/discord/discord_platform_adapter.py index 7657962a1..1640e8e40 100644 --- a/astrbot/core/platform/sources/discord/discord_platform_adapter.py +++ b/astrbot/core/platform/sources/discord/discord_platform_adapter.py @@ -348,6 +348,8 @@ class DiscordPlatformAdapter(Platform): timeout=10, ) logger.info("[Discord] 指令清理完成。") + except asyncio.TimeoutError: + logger.warning("[Discord] 清理指令超时,跳过。") except Exception as e: logger.error(f"[Discord] 清理指令时发生错误: {e}", exc_info=True) logger.info("[Discord] 正在关闭 Discord 客户端... (step 3)")