Files
loki/scripts/install-loki-app.sh
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00

105 lines
3.7 KiB
Bash

#!/usr/bin/env bash
# install-loki-app.sh — build and install Loki 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-loki-app.sh [--skip-build]
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
SERVICE_NAME="loki-app"
SERVICE_FILE="$HOME/.config/systemd/user/${SERVICE_NAME}.service"
STANDALONE="$PROJECT_DIR/.next/standalone"
log() { echo "[install-loki-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"
pnpm 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=Loki — Life OS (local production server)
Documentation=https://github.com/bitbaum/loki
After=network.target
[Service]
Type=simple
WorkingDirectory=${STANDALONE}
ExecStart=${SCRIPT_DIR}/loki-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 "✓ Loki 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