107 lines
3.4 KiB
Shell
107 lines
3.4 KiB
Shell
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
expected_machine_id="caa7b1019517470f9d1368b6e79db49e"
|
|
receipt_root="/var/lib/guanghu/language-primary/receipts"
|
|
services=(
|
|
"bingshuo-tcs-living-controller.service"
|
|
"guanghu-ai-discovery.service"
|
|
"lake-lamp-authz.service"
|
|
"lake-lamp-architecture-provision.service"
|
|
"lake-lamp-deployment-event-worker.service"
|
|
)
|
|
|
|
test "$(cat /etc/machine-id)" = "${expected_machine_id}"
|
|
install -d -o root -g root -m 0700 "${receipt_root}"
|
|
|
|
ready=0
|
|
controller_json=""
|
|
authz_json=""
|
|
public_code_http="000"
|
|
public_anchor_http="000"
|
|
for _attempt in $(seq 1 30); do
|
|
services_ready=1
|
|
for service in "${services[@]}"; do
|
|
if test "$(systemctl is-active "${service}")" != active; then
|
|
services_ready=0
|
|
fi
|
|
done
|
|
|
|
controller_json="$(
|
|
curl -fsS --max-time 3 http://127.0.0.1:3930/health 2>/dev/null || true
|
|
)"
|
|
authz_json="$(
|
|
curl -fsS --max-time 3 http://127.0.0.1:3921/health 2>/dev/null || true
|
|
)"
|
|
public_code_http="$(
|
|
curl -LfsS -o /dev/null -w '%{http_code}' --max-time 5 \
|
|
https://guanghulab.com/code/ 2>/dev/null || printf '000'
|
|
)"
|
|
public_anchor_http="$(
|
|
curl -LfsS -o /dev/null -w '%{http_code}' --max-time 5 \
|
|
https://guanghulab.com/api/ai/v1/anchor 2>/dev/null || printf '000'
|
|
)"
|
|
|
|
if test "${services_ready}" = 1 &&
|
|
jq -e '
|
|
."phase" == "RUNNING_COMPANION"
|
|
and ."execution_substrate.state" == "PASS_100"
|
|
and ."execution_substrate.linux_role" == "COOPERATIVE_EXECUTION_SUBSTRATE"
|
|
and ."execution_substrate.arbitrary_shell" == false
|
|
' <<<"${controller_json}" >/dev/null 2>&1 &&
|
|
jq -e '
|
|
.ok == true
|
|
and .merge_deployment_gate.configured == true
|
|
and .merge_deployment_gate.mode == "human-merged-pull-request-only"
|
|
' <<<"${authz_json}" >/dev/null 2>&1 &&
|
|
test "${public_code_http}" = 200 &&
|
|
test "${public_anchor_http}" = 200; then
|
|
ready=1
|
|
break
|
|
fi
|
|
sleep 2
|
|
done
|
|
test "${ready}" = 1
|
|
|
|
boot_id="$(cat /proc/sys/kernel/random/boot_id)"
|
|
observed_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
receipt="${receipt_root}/JD-FD-PRIMARY-LANGUAGE-PRIMARY-BOOT-${boot_id}.json"
|
|
world_target="$(readlink -f /guanghu/current)"
|
|
execution_release="$(readlink -f /opt/guanghu/execution-bridge/current)"
|
|
controller_receipt="$(
|
|
jq -r '.receipt_id' <<<"${controller_json}"
|
|
)"
|
|
|
|
jq -n \
|
|
--arg boot_id "${boot_id}" \
|
|
--arg observed_at "${observed_at}" \
|
|
--arg world_target "${world_target}" \
|
|
--arg execution_release "${execution_release}" \
|
|
--arg controller_receipt "${controller_receipt}" \
|
|
'{
|
|
schema: "guanghu.language-primary-boot-receipt/v1",
|
|
receipt_id: ("JD-FD-PRIMARY-LANGUAGE-PRIMARY-BOOT-" + $boot_id),
|
|
target_node_id: "JD-FD-PRIMARY",
|
|
boot_id: $boot_id,
|
|
control_role: "GUANGHU_OS_LANGUAGE_PRIMARY",
|
|
linux_role: "COOPERATIVE_EXECUTION_AND_RESCUE_SUBSTRATE",
|
|
world_target: $world_target,
|
|
execution_release: $execution_release,
|
|
controller_receipt: $controller_receipt,
|
|
world_gate: "PASS_100",
|
|
controller_gate: "PASS_100",
|
|
execution_substrate_gate: "PASS_100",
|
|
service_gate: "PASS_100",
|
|
public_code_http: 200,
|
|
public_anchor_http: 200,
|
|
arbitrary_shell: false,
|
|
boot_changed: false,
|
|
bare_metal_candidate_preserved: true,
|
|
observed_at: $observed_at,
|
|
result: "PASS_100"
|
|
}' >"${receipt}.tmp"
|
|
chmod 0600 "${receipt}.tmp"
|
|
mv "${receipt}.tmp" "${receipt}"
|
|
|
|
printf 'GUANGHU_LANGUAGE_PRIMARY_BOOT_PASS_100 receipt=%s\n' "${receipt}"
|
|
|