|
|
2 週間 前 | |
|---|---|---|
| runtime | 2 週間 前 | |
| scripts | 2 週間 前 | |
| substore | 3 週間 前 | |
| systemd | 3 週間 前 | |
| CLAUDE.md | 2 週間 前 | |
| README.md | 2 週間 前 | |
| config.json | 3 週間 前 |
一个用于 自动获取优选域名、写入 runtime/ 运行时文件,并按计划将运行时变更提交到 runtime-state 分支的工具。
本项目主要完成以下流程:
runtime/runtime-state核心脚本:
scripts/domain_updater.py:执行域名拉取、选择与写文件scripts/run_update_and_commit.sh:执行 updater + git 提交/推送scripts/install_debian.sh:Debian 下安装 systemd service + timerscripts/uninstall_debian.sh:卸载 systemd 与认证环境文件默认写入仓库根目录 runtime/:
runtime/current_domain.txt:当前域名(纯文本)runtime/current_domain.json:当前结果 JSONruntime/state.json:状态文件(含 last_good_domain)runtime/substore_vars.json:给外部系统消费的变量注意:
domain_updater.py现在会按--config文件所在目录解析output.runtime_dir(默认./runtime),避免误写到scripts/runtime/。
编辑 config.json。
典型解析路径(如 API 返回 data.good[].ip):
"parser": {
"field_paths": ["data.good[].ip"],
"json_paths": [],
"regex": "[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
}
python3 -m py_compile scripts/domain_updater.py
python3 -m py_compile scripts/update_vmess_links.py
python3 scripts/domain_updater.py --config config.json
cat runtime/current_domain.txt
cat runtime/current_domain.json
可选 HTTP 验证:
python3 -m http.server 8080 --directory runtime
curl http://127.0.0.1:8080/current_domain.json
git clone 到服务器(在仓库目录执行安装)origin 可用如果你采用“每台机器先手动保存 git 凭证”的流程,直接执行:
sudo bash scripts/install_debian.sh
默认行为:
sudo 执行前用户(SUDO_USER)1h--git-push 1)credential.helper storeruntime-state在服务用户下执行一次:
git config --global credential.helper store
git push origin runtime-state:runtime-state
首次输入用户名/密码(或 PAT)后,后续 systemd 可无交互 push。
关键点:保存凭证的用户必须和 service 的
User=一致。
sudo bash scripts/install_debian.sh \
--git-http-username <your-user> \
--git-http-token-file /root/.config/vmess-token \
--git-use-credential-store 1
sudo systemctl status vmess-domain-rotator.timer
sudo systemctl status vmess-domain-rotator.service
# 手动触发一次
sudo systemctl start vmess-domain-rotator.service
# 看日志
sudo journalctl -u vmess-domain-rotator.service -n 120 --no-pager
成功时应看到:
committed runtime changes on runtime-state ...pushed to origin/runtime-statesudo bash scripts/install_debian.sh [options]
| 参数 | 说明 | 默认值 |
|---|---|---|
--user <name> |
指定 service 用户 | 当前 sudo 用户 |
--group <name> |
指定 service 用户组 | 当前 sudo 用户主组 |
--interval <value> |
定时周期(如 1h/5min) |
1h |
| `--git-push <0 | 1>` | 是否自动 push |
--git-push-remote <name> |
远程名 | origin |
--git-http-username <u> |
HTTPS 认证用户名 | git |
--git-http-token <t> |
HTTPS token(明文参数) | 空 |
--git-http-token-file <f> |
从文件读取 token | 空 |
| `--git-use-credential-store <0 | 1>` | 是否使用 credential.helper store |
--git-credentials-file <f> |
指定 credential store 文件路径 | 空(Git 默认) |
--no-install-deps |
跳过 apt 安装依赖 | 关闭 |
-h, --help |
查看帮助 | - |
说明:
--git-push 1 时,push 失败会返回非 0,systemd 任务标记失败(便于监控)。/etc/vmess-domain-rotator.env。scripts/run_update_and_commit.sh 的行为:
domain_updater.py 更新根目录 runtime/runtime-state worktreeruntime/ 下四个文件同步到 runtime-state worktree--git-push 1 时要求 push 成功即:不再只看 main 分支当前文件是否变化,而是看 runtime-state 目标内容是否有变化。
sudo systemctl status vmess-domain-rotator.timer
sudo systemctl status vmess-domain-rotator.service
sudo systemctl start vmess-domain-rotator.service
sudo systemctl restart vmess-domain-rotator.timer
sudo journalctl -u vmess-domain-rotator.service -n 200 --no-pager
sudo journalctl -u vmess-domain-rotator.service -f
git log runtime-state --oneline -n 20
sudo bash scripts/uninstall_debian.sh
保留认证/env 文件:
sudo bash scripts/uninstall_debian.sh --keep-auth-files
python3 scripts/update_vmess_links.py \
--input ./nodes.txt \
--output ./nodes.updated.txt \
--domain-file ./runtime/current_domain.txt
仅替换匹配名称(ps)的节点:
python3 scripts/update_vmess_links.py \
--input ./nodes.txt \
--output ./nodes.updated.txt \
--domain-file ./runtime/current_domain.txt \
--name-regex "(argo|cf|vm)"
fatal: could not read Username ... terminal prompts disabledcredential.helper store 为明文存储,建议仅在可控服务器使用。runtime/state.json 需要持久化,保障 fallback 能用。