set -uo pipefail # claude/deploy startup profile: full supervised starts (leleka run) with the holder's sealed fd, phase lines, requests. V=@V@ COLD=@COLD@ STARTS=@STARTS@ R=$HOME/work/deploy-run/$V S=$HOME/work/deploy-run/state-$V A=/home/para/work/leleka/models/leleka-gates/assets M=$A/model CUBLAS=$HOME/cuda-toolkits/cublas-12.9.1.4/lib evict() { for f in "$@"; do dd if="$f" iflag=nocache count=0 status=none 2>/dev/null || true; done; } fincore $M/*.gguf 2>/dev/null; date -u +%FT%TZ; nvidia-smi --query-gpu=name,driver_version,memory.used --format=csv,noheader; free -g | head -2; sha256sum $R/bin/leleka-inference | cut -c1-16 rm -rf "$S"; cp -a $HOME/work/deploy-run/state "$S"; rm -rf "$S/logs" "$S/run" "$S/stamps/engine" $R/bin/leleka up --mode none --kar-fd "$LELEKA_STRA169_KAR_FD" --trust-archive --assets $A --state-dir "$S" --prefix $R --cublas-dir $CUBLAS 2>&1 | tail -3 | cut -c1-200 if [ "$COLD" = yes ]; then evict $M/*.gguf; echo "shards evicted from the page cache"; fi export LELEKA_BRINGUP_TRACE=1 one_start() { local label=$1 echo "################ start: $label ($(date -u +%T))" mv "$S/logs/engine.log" "$S/logs/engine.log.prev" 2>/dev/null local t0=$(date +%s.%N) $R/bin/leleka run --config "$S/leleka.json" --kar-fd "$LELEKA_STRA169_KAR_FD" > "$S/run.out" 2> "$S/run.err" & local UP=$! local ready=no for i in $(seq 1 600); do if $R/bin/leleka status --state-dir "$S" > /dev/null 2>&1; then ready=yes; break; fi kill -0 $UP 2>/dev/null || break sleep 0.5 done local t1=$(date +%s.%N) echo "ready=$ready start_to_ready=$(echo "$t1 - $t0" | bc) s" if [ "$ready" = yes ]; then local K=$(cat "$S/api-key") for n in 1 2; do curl -s -o /dev/null -w "request $n: http=%{http_code} total=%{time_total}s\n" -m 300 -H "Authorization: Bearer $K" -H 'content-type: application/json' \ -d '{"model":"qwen-iq3","input":"Reply with the single word: ready","max_output_tokens":8}' http://127.0.0.1:8081/v1/responses done fi kill -TERM $UP 2>/dev/null; wait $UP; echo "supervisor exit=$?" echo "--- phases (engine.log)"; grep -h "leleka-load-time" "$S/logs/engine.log" | cut -c1-160 echo "--- load ledger / stack stages"; grep -h -i -A45 "load ledger" "$S/logs/engine.log" | cut -c1-200 | head -70 echo "--- DBG begin lines"; grep -h "OriginalServeStack::open begin\|engine ready" "$S/logs/engine.log" | head echo "--- supervisor log"; grep -h "engine started\|model loaded\|ready:\|attested\|stamp" "$S/logs/leleka.log" | cut -c1-160 } for n in $(seq 1 $STARTS); do if [ $n = 1 ]; then one_start "first start of the service (cold=$COLD)"; else one_start "restart $n (stamps from the previous start)"; fi done ls -la "$S/stamps/engine" 2>/dev/null echo "--- leftovers"; pgrep -a -u "$USER" -f "deploy-run/$V/bin" | cut -c1-120 date -u +%FT%TZ