193 lines
6.8 KiB
Text
193 lines
6.8 KiB
Text
|
|
# provisioning-daemon — build, install, and lifecycle recipes
|
||
|
|
# ==============================================================
|
||
|
|
# Targets the HTTP+NATS daemon (crates/provisioning-daemon).
|
||
|
|
# Port: 9014 (PROVISIONING_DAEMON_BIND env overrides).
|
||
|
|
#
|
||
|
|
# nu-daemon — standalone build (excluded from platform workspace due to rustls conflict)
|
||
|
|
# Port: 9095. Binary: provisioning-nu-daemon → $HOME/.local/bin/
|
||
|
|
|
||
|
|
_prov_root := parent_directory(source_file()) / ".." # provisioning/
|
||
|
|
_platform := _prov_root / "platform"
|
||
|
|
_scripts := _platform / "scripts"
|
||
|
|
_bin := "provisioning-daemon"
|
||
|
|
_install := env_var_or_default("HOME", "/usr/local") / ".local" / "share" / "provisioning" / "bin"
|
||
|
|
|
||
|
|
_nu_daemon_crate := _platform / "crates" / "nu-daemon"
|
||
|
|
_nu_daemon_bin := "provisioning-nu-daemon"
|
||
|
|
_nu_daemon_install := env_var_or_default("HOME", "/usr/local") / ".local" / "bin"
|
||
|
|
_log := "/tmp/provisioning-daemon.log"
|
||
|
|
_pid := "/tmp/provisioning-daemon.pid"
|
||
|
|
|
||
|
|
# ── Build ──────────────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
# Build provisioning-daemon in release mode
|
||
|
|
daemon-build:
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
echo "=== build: cargo build --release --bin {{_bin}} ==="
|
||
|
|
cargo build --release \
|
||
|
|
--manifest-path "{{_platform}}/Cargo.toml" \
|
||
|
|
--bin "{{_bin}}"
|
||
|
|
echo " binary: {{_platform}}/target/release/{{_bin}}"
|
||
|
|
|
||
|
|
# Build in dev mode (faster, larger binary)
|
||
|
|
daemon-build-dev:
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
cargo build \
|
||
|
|
--manifest-path "{{_platform}}/Cargo.toml" \
|
||
|
|
--bin "{{_bin}}"
|
||
|
|
echo " binary: {{_platform}}/target/debug/{{_bin}}"
|
||
|
|
|
||
|
|
# Run all tests for provisioning-daemon
|
||
|
|
daemon-test:
|
||
|
|
cargo test \
|
||
|
|
--manifest-path "{{_platform}}/Cargo.toml" \
|
||
|
|
-p provisioning-daemon \
|
||
|
|
--lib
|
||
|
|
|
||
|
|
# Run clippy on provisioning-daemon
|
||
|
|
daemon-lint:
|
||
|
|
cargo clippy \
|
||
|
|
--manifest-path "{{_platform}}/Cargo.toml" \
|
||
|
|
-p provisioning-daemon \
|
||
|
|
-- -D warnings
|
||
|
|
|
||
|
|
# ── Install ────────────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
# Install provisioning-daemon to ~/.local/share/provisioning/bin/
|
||
|
|
daemon-install: daemon-build
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
mkdir -p "{{_install}}"
|
||
|
|
install -m 0755 "{{_platform}}/target/release/{{_bin}}" "{{_install}}/{{_bin}}"
|
||
|
|
echo " installed: {{_install}}/{{_bin}}"
|
||
|
|
|
||
|
|
# Build + install + restart in one step
|
||
|
|
daemon-deploy: daemon-install
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
echo "=== deploy: stopping existing daemon ==="
|
||
|
|
if [ -f "{{_pid}}" ]; then
|
||
|
|
PID=$(cat "{{_pid}}" | tr -d '[:space:]')
|
||
|
|
if [ -n "$PID" ] && kill -0 "$PID" 2>/dev/null; then
|
||
|
|
kill "$PID"
|
||
|
|
sleep 1
|
||
|
|
fi
|
||
|
|
rm -f "{{_pid}}"
|
||
|
|
fi
|
||
|
|
echo "=== deploy: starting daemon ==="
|
||
|
|
nohup "{{_install}}/{{_bin}}" >> "{{_log}}" 2>&1 &
|
||
|
|
echo $! > "{{_pid}}"
|
||
|
|
echo " PID: $(cat {{_pid}}) log: {{_log}}"
|
||
|
|
# wait for health
|
||
|
|
for i in $(seq 1 10); do
|
||
|
|
if curl -sf http://127.0.0.1:9014/health > /dev/null 2>&1; then
|
||
|
|
echo " health: ok"
|
||
|
|
break
|
||
|
|
fi
|
||
|
|
sleep 1
|
||
|
|
done
|
||
|
|
|
||
|
|
# ── Lifecycle ──────────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
# Start daemon in background (uses installed binary or release build)
|
||
|
|
daemon-start:
|
||
|
|
nu "{{_scripts}}/start-provisioning-daemon.nu" start
|
||
|
|
|
||
|
|
# Stop running daemon
|
||
|
|
daemon-stop:
|
||
|
|
nu "{{_scripts}}/start-provisioning-daemon.nu" stop
|
||
|
|
|
||
|
|
# Show daemon status and health
|
||
|
|
daemon-status:
|
||
|
|
nu "{{_scripts}}/start-provisioning-daemon.nu" status
|
||
|
|
|
||
|
|
# Restart daemon
|
||
|
|
daemon-restart:
|
||
|
|
nu "{{_scripts}}/start-provisioning-daemon.nu" restart
|
||
|
|
|
||
|
|
# Tail daemon logs
|
||
|
|
daemon-logs:
|
||
|
|
nu "{{_scripts}}/start-provisioning-daemon.nu" logs
|
||
|
|
|
||
|
|
# ── Dev helpers ────────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
# Run daemon in foreground with debug logging (dev mode)
|
||
|
|
daemon-run:
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
RUST_LOG=debug \
|
||
|
|
cargo run \
|
||
|
|
--manifest-path "{{_platform}}/Cargo.toml" \
|
||
|
|
--bin "{{_bin}}"
|
||
|
|
|
||
|
|
# Run daemon with custom bind address
|
||
|
|
daemon-run-bind bind="0.0.0.0:9014":
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
RUST_LOG=info \
|
||
|
|
cargo run \
|
||
|
|
--manifest-path "{{_platform}}/Cargo.toml" \
|
||
|
|
--bin "{{_bin}}" \
|
||
|
|
-- --bind "{{bind}}"
|
||
|
|
|
||
|
|
# Query health endpoint
|
||
|
|
daemon-health:
|
||
|
|
curl -sf http://127.0.0.1:9014/health | jq .
|
||
|
|
|
||
|
|
# List registered tools via daemon API
|
||
|
|
daemon-tools:
|
||
|
|
curl -sf http://127.0.0.1:9014/api/v1/tools | jq '.tools[] | {name, category}'
|
||
|
|
|
||
|
|
# List ontology templates (requires JWT or solo mode)
|
||
|
|
daemon-ontology-list:
|
||
|
|
curl -sf http://127.0.0.1:9014/api/v1/ontology/templates | jq .
|
||
|
|
|
||
|
|
# Open admin UI in browser
|
||
|
|
daemon-ui:
|
||
|
|
open http://127.0.0.1:9014/admin/
|
||
|
|
|
||
|
|
# ── Watch (live-reload on config change) ──────────────────────────────────────
|
||
|
|
|
||
|
|
# Run daemon with config watcher on default paths
|
||
|
|
daemon-watch paths="":
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
WATCH_PATHS="${PROVISIONING_WATCH_PATHS:-{{paths}}}"
|
||
|
|
if [ -n "$WATCH_PATHS" ]; then
|
||
|
|
WATCH_FLAG="--watch-paths $WATCH_PATHS"
|
||
|
|
else
|
||
|
|
WATCH_FLAG=""
|
||
|
|
fi
|
||
|
|
RUST_LOG=info \
|
||
|
|
cargo run \
|
||
|
|
--manifest-path "{{_platform}}/Cargo.toml" \
|
||
|
|
--bin "{{_bin}}" \
|
||
|
|
-- $WATCH_FLAG
|
||
|
|
|
||
|
|
# ── nu-daemon (standalone — excluded from platform workspace) ─────────────────
|
||
|
|
|
||
|
|
# Build nu-daemon in release mode (must build standalone, not via workspace)
|
||
|
|
nu-daemon-build:
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
echo "=== build: cargo build --release (standalone) ==="
|
||
|
|
cargo build --release \
|
||
|
|
--manifest-path "{{_nu_daemon_crate}}/Cargo.toml"
|
||
|
|
echo " binary: {{_nu_daemon_crate}}/target/release/{{_nu_daemon_bin}}"
|
||
|
|
|
||
|
|
# Install nu-daemon to $HOME/.local/bin/
|
||
|
|
nu-daemon-install: nu-daemon-build
|
||
|
|
#!/usr/bin/env bash
|
||
|
|
set -euo pipefail
|
||
|
|
mkdir -p "{{_nu_daemon_install}}"
|
||
|
|
install -m 0755 \
|
||
|
|
"{{_nu_daemon_crate}}/target/release/{{_nu_daemon_bin}}" \
|
||
|
|
"{{_nu_daemon_install}}/{{_nu_daemon_bin}}"
|
||
|
|
echo " installed: {{_nu_daemon_install}}/{{_nu_daemon_bin}}"
|
||
|
|
|
||
|
|
# Build + install in one step
|
||
|
|
nu-daemon-deploy: nu-daemon-install
|
||
|
|
@echo " deployed: {{_nu_daemon_bin}} → {{_nu_daemon_install}}"
|