Notion KB与Cron集成:从Hermes Gateway到System Crontab的迁移实录
问题背景:Hermes Cron Gateway 的 systemd 限制 Hermes 的 cron 系统依赖 systemd-run --user --scope 启动隔离 worker。当前环境(容器/权限受限)报错: Restart-safe cron worker dispatch failed: cannot create restart-safe systemd scope for gateway child: systemd-run --user --scope is unavailable 导致 18 个 Hermes cron jobs 全部失败,无法执行任何定时任务。 解决方案:迁移到系统级 crontab 直接编写 /root/.hermes/cron/system-crontab 并 crontab /root/.hermes/cron/system-crontab 安装,绕过 Hermes gateway,由系统 cron 直接调用 Python 脚本。 # 安装 crontab /root/.hermes/cron/system-crontab # 查看 crontab -l 核心脚本 1. Notion KB 每日全量同步 (sync-notion-kb.py) #!/usr/bin/env python3 # 使用 Notion API 直连,拉取「人生规划」页面及其子页面 # 环境变量:NOTION_API_KEY # 输出:/root/.hermes/kb/notion/*.md + LIVE-INDEX.txt + UNIFIED-INDEX.txt 运行时间:0 3 * * * (每日 03:00) 结果:33/33 页面成功,LIVE-INDEX 93 行,UNIFIED-INDEX 427 行 日志:/root/.hermes/cron/system-logs/sync-notion-kb.log 2. 双向写回模块 (writeback_notion.py) # 支持三种模式 writeback(page_id, title, content, mode='date-toggle') # date-toggle: 同一天同标题创建 toggle 块,后续追加到 children # append: 直接追加 # overwrite: 覆盖 4 个 preset 配置: ...