Files
loki/scripts/install-fleetcrown-app.sh
T
Mao NakamotoandClaude Opus 4.8 7432f16053 refactor(runner): rename daemon→runner across the live system, keep legacy contracts
The bash daemon was deleted in Session 4 of killing-the-bash-daemon; Fleet
Runner (the desktop poller) is the local executor now. This retires the
'daemon' name from everything describing the live system — constants
(DAEMON_*→RUNNER_*), types (DaemonStateKey→RunnerStateKey), the status
banner component, state-derivation fns, control props, CSS classes
(ui-control-fleet-daemon→-runner), and comments/UI strings.

Backward-compat shims (no breakage to deployed Fleet Runner installs):
- src/lib/constants/daemon.ts re-exports RUNNER_* under the old DAEMON_*
  names for the desktop Electron build until it points at the runner path.
- Fleet Doctor reads runner.env, falls back to legacy daemon.env.

Deliberately KEPT as 'daemon' (they name the genuinely-dead/legacy thing):
the deprecated DAEMON_TOKEN bearer contract, the /api/agent/daemon 410
tombstone, the legacyDaemon developer download, and historical
killing-the-bash-daemon references. systemctl daemon-reload / NX_DAEMON
left untouched (not ours).

tsc clean · eslint 0 errors · test:home 97/97 · smoke 44/44

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 01:05:12 +02:00

105 lines
3.7 KiB
Bash

#!/usr/bin/env bash
# install-fleetcrown-app.sh — build and install FleetCrown as a systemd user service.
#
# Run once after cloning, and again after significant dependency changes.
# The service auto-starts on login and restarts on crash.
#
# Usage: ./scripts/install-fleetcrown-app.sh [--skip-build]
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
SERVICE_NAME="fleetcrown-app"
SERVICE_FILE="$HOME/.config/systemd/user/${SERVICE_NAME}.service"
STANDALONE="$PROJECT_DIR/.next/standalone"
log() { echo "[install-fleetcrown-app] $*"; }
# ── 1. Build ──────────────────────────────────────────────────────────────────
SKIP_BUILD=0
for arg in "$@"; do
[ "$arg" = "--skip-build" ] && SKIP_BUILD=1
done
if [ "$SKIP_BUILD" = "0" ]; then
log "Building production bundle (this takes ~2 minutes)…"
cd "$PROJECT_DIR"
npm run build
log "Build complete."
else
log "Skipping build (--skip-build)."
fi
# ── 2. Copy static assets into standalone ────────────────────────────────────
# next build --output standalone does NOT copy .next/static or public/ —
# they must be present alongside server.js for assets to be served.
log "Copying static assets to standalone…"
# Remove first so repeated installs don't nest directories (cp -r into an existing
# dir copies the source as a subdirectory of the dest, not the contents into it).
rm -rf "$STANDALONE/.next/static" "$STANDALONE/public"
cp -r "$PROJECT_DIR/.next/static" "$STANDALONE/.next/static"
cp -r "$PROJECT_DIR/public" "$STANDALONE/public"
log "Static assets copied."
# ── 3. Write systemd user service ────────────────────────────────────────────
mkdir -p "$HOME/.config/systemd/user"
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=FleetCrown — Life OS (local production server)
Documentation=https://github.com/maonakamoto/fleetcrown
After=network.target
[Service]
Type=simple
WorkingDirectory=${STANDALONE}
ExecStart=${SCRIPT_DIR}/fleetcrown-app.sh
Restart=on-failure
RestartSec=5
# Next's standalone server can hold open instrumentation resources on SIGTERM.
# Bound unattended deploy restarts instead of blocking postbuild for 90 seconds.
TimeoutStopSec=5
# Log to journald — view with: journalctl --user -u ${SERVICE_NAME} -f
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=default.target
EOF
log "Service file written to $SERVICE_FILE"
# ── 4. Enable and start ───────────────────────────────────────────────────────
systemctl --user daemon-reload
systemctl --user enable "$SERVICE_NAME"
if systemctl --user is-active --quiet "$SERVICE_NAME"; then
log "Restarting $SERVICE_NAME…"
systemctl --user restart "$SERVICE_NAME"
else
log "Starting $SERVICE_NAME…"
systemctl --user start "$SERVICE_NAME"
fi
# Give the server a moment to bind.
sleep 2
STATUS=$(systemctl --user is-active "$SERVICE_NAME" 2>/dev/null || echo "unknown")
if [ "$STATUS" = "active" ]; then
PORT=$(grep "^PORT=" "$PROJECT_DIR/.env.local" 2>/dev/null | cut -d= -f2 || echo "3000")
PORT="${PORT:-3000}"
log "✓ FleetCrown is running at http://localhost:${PORT}"
log " Manage with: systemctl --user {status|stop|restart|logs} ${SERVICE_NAME}"
log " View logs: journalctl --user -u ${SERVICE_NAME} -f"
else
log "✗ Service did not start (status: $STATUS)"
log " Check logs: journalctl --user -u ${SERVICE_NAME} -n 50"
exit 1
fi