Menu
AkurAI-Build
publicLatest change fab22f173067842a9635889fa6c4c63436e6bd6f - Deploy job hands off to the host agent and exits before the restart by Ólafur Búi Ólafsson
#!/bin/sh
# Host-side deploy agent for akurai-build. Runs as root via akurai-deploy.service
# (triggered by akurai-deploy.path) whenever a CI deploy job stages a request.
#
# Contract with deploy/service-deploy.sh (which runs inside the sandboxed CI
# job and can only write beneath the service data dir):
# staging/akurai.next candidate binary
# staging/request sha256 of the candidate (written last, atomically)
# staging/result "ok" or failure reason, written by this agent
set -eu
staging=/home/olibuijr/.local/share/akurai-build/deploy-staging
bin=/home/olibuijr/.local/lib/akurai-build/akurai
health_url=http://127.0.0.1:3210/api/health
request="$staging/request"
candidate="$staging/akurai.next"
result="$staging/result"
[ -f "$request" ] || exit 0
fail() {
printf '%s\n' "$1" > "$result.tmp"
mv "$result.tmp" "$result"
chown olibuijr:olibuijr "$result" 2>/dev/null || true
rm -f "$request" "$candidate"
exit 0
}
expected=$(cat "$request")
actual=$(sha256sum "$candidate" | cut -d' ' -f1) || fail "candidate binary missing"
[ "$expected" = "$actual" ] || fail "checksum mismatch: expected $expected got $actual"
# Let the CI deploy job that staged this request record its success and exit
# before we restart the service it runs inside of.
sleep 10
cp "$bin" "$bin.previous"
install -o olibuijr -g olibuijr -m 755 "$candidate" "$bin.next"
mv "$bin.next" "$bin"
systemctl restart akurai-build
attempt=0
while [ "$attempt" -lt 30 ]; do
if curl -fsS "$health_url" >/dev/null 2>&1; then
rm -f "$bin.previous" "$request" "$candidate"
printf 'ok\n' > "$result.tmp"
mv "$result.tmp" "$result"
chown olibuijr:olibuijr "$result" 2>/dev/null || true
exit 0
fi
attempt=$((attempt + 1))
sleep 2
done
mv "$bin.previous" "$bin"
systemctl restart akurai-build
fail "replacement service did not become healthy; rolled back"