fix: restore Trojan certificates and schedule host renewals

This commit is contained in:
chermack
2026-10-24 02:19:51 +08:00
parent 39255cc3dc
commit de8e02b33f
7 changed files with 330 additions and 21 deletions
+36
View File
@@ -6,3 +6,39 @@
4. 使用 `verify.sh` 验证管理端、证书、Trojan 监听与公开 443 分享链接。
5. 正式切换时停止并重命名旧容器为 `trojan-legacy`,再以本 compose 启动新容器。
6. 任一核心检查失败,立即运行 `rollback.sh`。保留旧容器至少一个证书续期周期。
## Docker 证书自动续期(2026-10-24 修正)
兼容镜像使用 `systemctl.py`,容器中的 `.timer` 不会实际调度。必须在
**宿主机**安装仓库 `trojan-stack/scripts/` 下的脚本和 systemd 单元:
```bash
install -m 0755 trojan-stack/scripts/renew-certificate-host.py /usr/local/sbin/renew-trojan-certificate-host.py
install -m 0644 trojan-stack/scripts/trojan-certificate-renew.service /etc/systemd/system/
install -m 0644 trojan-stack/scripts/trojan-certificate-renew.timer /etc/systemd/system/
systemd-analyze verify /etc/systemd/system/trojan-certificate-renew.service /etc/systemd/system/trojan-certificate-renew.timer
systemctl daemon-reload
systemctl enable --now trojan-certificate-renew.timer
systemctl start trojan-certificate-renew.service
systemctl list-timers --all trojan-certificate-renew.timer
journalctl -u trojan-certificate-renew.service -n 80 --no-pager
```
依赖宿主机 Python 3、OpenSSL、Docker CLI 和真实 systemd。默认操作 `trojan`
容器,配置与证书必须使用持久化 bind mount。域名与实际证书路径从现有
`/usr/local/etc/trojan/config.json` 读取,当前实现针对 ECC 证书。
HTTP-01 使用 `/var/lib/trojan-acme-webroot`,宿主机 Nginx 的
`/.well-known/acme-challenge/` 必须转发到现有 `127.0.0.1:8082` 常驻文件服务。
初次从旧 standalone 配置迁移时先使用 `acme.sh --issue --webroot
/var/lib/trojan-acme-webroot -d <域名> --keylength ec-256` 签发;之后脚本按
到期计划调用 `--renew --ecc --webroot`,不用 `--force`。
定时器每天 03:00、15:00(宿主机时区)加 0–30 分钟随机延迟检查,开机后
5 分钟也检查,并补执行关机期间错过的日历任务。脚本使用文件锁防并发;
校验至少 7 天有效期、域名、ECC/RSA 通用公钥匹配,然后部署到配置指定路径。
只有运行中证书指纹与文件不同才重启 Trojan,最后校验运行端口 TLS 信任链、
域名与证书指纹。失败会使 service 返回非零并写入 journal;尚未接入外部通知。
容器内旧 `trojan-acme-renew.timer` 与旧 acme.sh crontab 应停用,避免未来启动
cron 后出现两套调度。安装宿主机定时器不需要重建或重启整个容器。