Skip to content

hook test —— 本地试运行 ​

使用模拟数据在本机试运行 hook,不改动真实证书,CertiMan 本身不访问网络。用于验证 hook 脚本自身的逻辑。

present 步骤成功后自动执行 cleanup,模拟一次完整的 DCV 流程。

用法 ​

bash
certiman hook test [flags]

参数 ​

flag短名类型默认说明
--domain-d[]string选择器:按主域名指定本机证书,以其配置作为数据来源
--conf-cstring选择器:证书配置文件路径
--stepstringpresent试运行步骤:present / cleanup / deploy
--keepboolfalse仅对 --step present 有效:present 成功后不自动执行 cleanup,便于在 DNS 服务商控制台手动核对记录

示例 ​

bash
# 试运行 present(成功后自动执行 cleanup)
certiman hook test -d example.com

# 只试运行 deploy
certiman hook test -d example.com --step deploy

# 用外部配置文件
certiman hook test -c ./shop-cert.yaml --step present

输出 ​

0成功(示例,腾讯云 DNS hook)
text
» 试运行 present hook(模拟数据,不访问网络):example.com
[hook:present] [tc-present] 已布置 TXT _dnsauth.example.com = certiman-hook-test-20260808012043 (RecordId=2363165357,剩余 0)
[hook:present] [tc-present] 全部布置完成,等待 DNS 传播 20s...
✔ present hook 退出码 0
» 自动清理试运行写下的记录
[hook:cleanup] [tc-cleanup] 已删除 RecordId=2363165357(_dnsauth.example.com,结果 success)
✔ cleanup hook 退出码 0

试运行注入的模拟值带有 certiman-hook-test- 前缀,便于在 DNS 服务商控制台中识别。present 成功后,CertiMan 自动执行一次 cleanup,避免在 DNS 服务商侧残留试运行记录。

hook 未被执行时(退出码 126 / 127)

路径错误、脚本缺少执行权限(未执行 chmod +x)、在 Windows 上使用 shebang 脚本等问题,在 hook test 中会以退出码 126(不可执行)或 127(不存在)体现。含义与建议动作见 Hook 环境变量 · 退出码 126 与 127。

正式流程中的 hook 输出写入日志

由 issue、renew、cron 等命令触发的 hook,其 stdout / stderr 会按行写入 ~/.certiman/logs/cc-YYYY-MM.log。定时任务执行失败时,可用 tail 查看该日志中的脚本原始输出。

1脚本缺环境变量(示例)
text
» 试运行 present hook(模拟数据,不访问网络):example.com
[hook:present] Traceback (most recent call last):
[hook:present]   File "./tc_dns.py", line 53, in <module>
[hook:present]     main()
[hook:present]     ~~~~^^
[hook:present]   File "./tc_dns.py", line 15, in main
[hook:present]     secret_id = os.environ["TENCENTCLOUD_SECRET_ID"]
[hook:present]                 ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
[hook:present]   File "<frozen os>", line 709, in __getitem__
[hook:present] KeyError: 'TENCENTCLOUD_SECRET_ID'
2026-08-07 19:32:35.545 ERROR hook finished hook=present command=./tc-present.sh duration_ms=212 env_keys=…(略) exit_code=1
错误: present hook 退出码 1
日志: ~/.certiman/logs/cc-2026-08.log

相关命令 ​