The uri probe ran 1s after the service (re)start while the adapter still accepts TCP but doesn't yet answer (read hangs); uri's default 30s timeout + retries/until did not actually loop on a connection timeout, so it failed after one attempt. Replace with a curl retry loop (5s per attempt, up to ~30 tries) — the adapter answers acp.capabilities in ~4ms once ready. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
2.4 KiB
YAML
61 lines
2.4 KiB
YAML
---
|
||
- name: Validate Caddy configuration
|
||
ansible.builtin.command: caddy validate --config "{{ acp_opencode_caddyfile_path }}"
|
||
changed_when: false
|
||
when: acp_opencode_manage_caddy | bool
|
||
|
||
- name: Check OpenCode ACP listener
|
||
ansible.builtin.shell: |
|
||
if command -v ss >/dev/null 2>&1; then
|
||
ss -ltnp
|
||
else
|
||
lsof -nP -iTCP -sTCP:LISTEN 2>/dev/null || true
|
||
fi
|
||
args:
|
||
executable: /bin/bash
|
||
register: acp_opencode_ss
|
||
changed_when: false
|
||
failed_when: false
|
||
|
||
# 用 curl 重试循环替代 uri:服务刚 (重)启时 adapter 会先 accept TCP 但短时间内不
|
||
# 应答(读挂起),而 uri 默认 30s 超时 + retries/until 在连接超时上不可靠循环(实测
|
||
# 仅试一次即失败)。每次 5s 上限、真重试,给冷启动足够时间(adapter 就绪后 ~4ms 回 200)。
|
||
- name: Validate OpenCode local ACP endpoint (readiness retry)
|
||
ansible.builtin.shell: |
|
||
set -eu
|
||
url="http://{{ acp_opencode_listen_host }}:{{ acp_opencode_listen_port }}/acp/rpc"
|
||
body='{"jsonrpc":"2.0","id":1,"method":"acp.capabilities","params":{}}'
|
||
code=""
|
||
for i in $(seq 1 30); do
|
||
code="$(curl -s -m 5 -o /dev/null -w '%{http_code}' -X POST "$url" \
|
||
-H 'Content-Type: application/json' -d "$body" 2>/dev/null || true)"
|
||
if [ "$code" = "200" ]; then
|
||
echo "OpenCode ACP endpoint ready after ${i} attempt(s)"
|
||
exit 0
|
||
fi
|
||
sleep 2
|
||
done
|
||
echo "OpenCode ACP endpoint ${url} not ready after retries (last code: ${code:-none})" >&2
|
||
exit 1
|
||
args:
|
||
executable: /bin/bash
|
||
changed_when: false
|
||
register: acp_opencode_adapter_probe
|
||
|
||
- name: Show OpenCode ACP status
|
||
ansible.builtin.command: systemctl status "{{ acp_opencode_service_name }}" --no-pager
|
||
register: acp_opencode_status
|
||
changed_when: false
|
||
failed_when: false
|
||
|
||
- name: Show OpenCode ACP validation summary
|
||
ansible.builtin.debug:
|
||
msg:
|
||
- "OpenCode public base URL: {{ acp_opencode_public_base_url }}"
|
||
- "Preferred WebSocket endpoint: {{ acp_opencode_public_base_url }}/acp"
|
||
- "Compatibility HTTP RPC endpoint: {{ acp_opencode_public_base_url }}/acp/rpc"
|
||
- "OpenCode ACP adapter listener: {{ acp_opencode_listen_host }}:{{ acp_opencode_listen_port }}"
|
||
- "Service: {{ acp_opencode_status.stdout | default('N/A') }}"
|
||
- "Socket: {{ acp_opencode_ss.stdout | default('N/A') }}"
|
||
- "Adapter capabilities HTTP: {{ acp_opencode_adapter_http.content | default('N/A') }}"
|