You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telethon Bot通过systemd启动后无响应问题排查请求

排查Telethon Bot systemd启动无响应问题

1. 补全工作目录配置

systemd默认工作目录为/,而直接运行脚本时是在脚本所在目录,Bot可能依赖当前目录下的会话文件、配置文件等资源。在[Service]块中添加工作目录配置:

WorkingDirectory=/home/django/Shutova_assist/

2. 强制输出日志到文件

默认systemd日志可能未捕获到Bot的完整输出,添加日志重定向配置便于排查:
在[Service]块中添加:

StandardOutput=append:/var/log/shutova_bot.log
StandardError=append:/var/log/shutova_bot.log

修改后重启服务,交互Bot后查看日志:cat /var/log/shutova_bot.log

3. 修复文件权限归属

直接以root运行脚本时,生成的会话文件等资源会属于root用户,导致systemd用django用户启动时无法读取。执行命令修复目录权限:

sudo chown -R django:django /home/django/Shutova_assist/

4. 同步环境变量

systemd的默认环境变量与终端直接运行时存在差异,可能导致Bot依赖的路径或变量缺失。在[Service]块中添加必要环境变量:

Environment="PATH=/usr/local/bin:/usr/bin:/bin"
# 若Bot依赖用户自定义环境变量,可导入用户配置文件
EnvironmentFile=/home/django/.bashrc

5. 调整服务类型

尝试将Type=simple改为Type=exec,避免进程管理异常:

Type=exec

6. 查看服务详细状态

执行以下命令获取服务的进程细节和隐藏日志:

sudo systemctl status shutova -l
sudo journalctl -u shutova -f

即使服务显示active,journalctl可能会输出未被捕获的警告信息。

内容的提问来源于stack exchange,提问作者user15066710

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 06:47:04