---
title: "Headless LiveSync Server Runbook"
description: "A public runbook for running Self-hosted LiveSync CLI as a headless server-side Obsidian peer."
date: 2026-06-21
tags:
  - obsidian
  - livesync
  - couchdb
  - runbook
category: tech
publish: true
---

# Headless LiveSync Server Runbook

Companion note for [unified-agent-memory-fabric](/unified-agent-memory-fabric.md).

## Why this exists

The server needs to participate in Obsidian LiveSync without running the Obsidian GUI. The critical idea is path separation: one path for LiveSync runtime state, one path for the actual vault.

## Spec

# Headless LiveSync on server

## Purpose

server participates in the same CouchDB LiveSync network as mac, phone, and iPad without running the Obsidian GUI app.

This lets:

- mobile or mac edits materialize into `/srv/vault-write`
- cloud agent edits under `/srv/vault-write` propagate to CouchDB
- gbrain index a filesystem that stays close to current vault reality

## Working deployment

### Paths

- LiveSync CLI database path: `/srv/livesync-db`
- Real vault path: `/srv/vault-write`
- CLI source path: `/opt/obsidian-livesync/src/apps/cli`
- Node binary: `/srv/.nvm/versions/node/v22.21.1/bin/node`
- Service file: `/etc/systemd/system/livesync-daemon.service`

### Service command

```bash
/srv/.nvm/versions/node/v22.21.1/bin/node \
  /opt/obsidian-livesync/src/apps/cli/dist/index.cjs \
  /srv/livesync-db \
  --vault /srv/vault-write \
  daemon
```

### Systemd checks

```bash
systemctl status livesync-daemon --no-pager
journalctl -u livesync-daemon --no-pager -n 60
```

Expected log lines:

```text
[Daemon] Mirror scan complete
[Daemon] LiveSync mode: restoring sync settings and starting _changes feed
[Daemon] LiveSync active
```

## Root cause of earlier failures

The failed attempts used the actual vault as the CLI database path. That collapsed these two roles:

- CLI local database/runtime state
- real Obsidian vault files

That produced confusing `legacy-couchdb` migration behavior and unreliable daemon startup.

The fix was to create a separate database directory and pass the real vault through `--vault`.

## Verified behavior

server-written lines appeared on mac and mobile without a git commit:

- `NATIVE-LIVESYNC-SEPARATE-DB TEST 21:08:41`
- `VERBOSE-WATCH-TEST 21:10:50`

This verifies server filesystem to CouchDB to clients.

## Verification — both directions, and the trap in this runbook

**Update 2026-09-04.** Both directions are now verified. Getting there exposed a flaw in the
verification step this runbook originally recommended, so read this before testing anything.

### Never name a test file `TEST-`

The original instruction was to write `TEST-LIVESYNC-FROM-ORACLE.md` and look for it on the other
side. That test **can never pass** if your `syncIgnoreRegEx` contains `^TEST-`, which is a natural
thing to add once you get tired of test files replicating to your phone.

An ignored file produces no log line and no error. It simply never becomes a document. The result
is a healthy daemon that looks completely dead, and hours spent debugging a system that was working.
That is exactly what happened here.

Check your ignore list before choosing a filename, and prefix canaries with something neutral:

```bash
# server -> clients
echo hi > "/srv/vault-write/canary-$(date -u +%H%M%S).md"

# clients -> server
grep -R "some unique string" /srv/vault-write
```

### Set a device name

`deviceAndVaultName` must be set and distinct on every peer — LiveSync uses it for conflict
attribution. An empty value on the headless daemon is easy to miss because nothing complains.

### Judge the daemon by its log, not by systemd

`systemctl is-active` reported `active` throughout a real failure. The unit state tells you the
process exists, nothing more. Alert on the age of the newest journal line and on a canary
round-trip instead.

### Polling mode

If the long-lived `_changes` feed proves unreliable in your environment, the CLI supports polling:

```bash
node dist/index.cjs /srv/livesync-db --vault /srv/vault-write daemon --interval 30
```

That is the configuration running here.

## What deletion really looks like (update 2026-10-10)

Deletes are the part of LiveSync that hurts, so these are the measured facts.

- **A LiveSync delete is a field, not a CouchDB delete.** The document stays and carries `deleted: true` in its body. CouchDB's own `doc_del_count` therefore says almost nothing; count documents whose body is flagged.
- **Any peer can delete for everyone.** When one peer's disk or local database is incomplete, "the remote has files I do not have" is indistinguishable from "I deleted them". That is how 413 documents vanished on the Mac in the early-September incident.
- **Resurrection is the mirror image.** A peer with live sync switched off, or with a stale checkpoint, brings deleted files back when it reconnects.
- **The Mac sends every applied tombstone to the system Trash.** A mass delete-plus-write shows up there as a wave of files the next morning.
- **Delete in two steps:** tombstone the document in CouchDB, then remove the file on disk. Removing only the file leaves a live document.
- **The headless daemon starts from a clean local database every time.** After a warm restart, the bundled CLI mistook files it could not pair for deletions (about 1,800 documents were flagged after a 47-minute warm restart, with every file present on disk the whole time). A fresh local database cannot reach that code path, so the service wrapper archives the database before each start. The cost is roughly two minutes of re-replication per restart and about 55 MB of archive each time, so watch the archive directory. The CLI bundle is unchanged, so the workaround is still needed.
- **Judge it with a canary.** A nightly job writes a note, waits for it to appear in CouchDB, deletes it, and waits for the tombstone. Measured: about two seconds each way.

## Do not do these

- Do not run `git rebase`, `pull`, `reset`, `checkout` or `stash` inside the live vault. A nightly rebase that conflicted and aborted still rewrote about 500 files, and LiveSync replicated every one of them.
- Do not point cloud agents at `/srv/livesync-db`.
- Do not use `/srv/vault-write` as both database path and vault path.
- Do not patch LiveSync JSON settings by guessing. Read docs or source first.
- Do not commit large deletion sets from `git status` unless deletion intent is confirmed.

## Durability gap

The CLI source currently lives under `/opt/obsidian-livesync`. Move it to a durable path before considering this production-hardened, for example:

```text
/srv/services/obsidian-livesync
```

Then update the systemd service to point there.


---

## Setup notes

# server headless LiveSync setup notes

## Verified command

```bash
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
cd /opt/obsidian-livesync/src/apps/cli
node dist/index.cjs /srv/livesync-db --vault /srv/vault-write daemon
```

## Required settings file

Path:

```text
/srv/livesync-db/.livesync/settings.json
```

Do not commit this file because it contains CouchDB credentials.

Minimum required fields:

```json
{
  "remoteType": "couchdb",
  "couchDB_URI": "https://couchdb.livesync.goku.codes",
  "couchDB_USER": "admin",
  "couchDB_PASSWORD": "REDACTED",
  "couchDB_DBNAME": "vault-write",
  "isConfigured": true,
  "liveSync": true,
  "syncOnStart": true,
  "syncOnSave": true,
  "syncOnEditorSave": true,
  "keepReplicationActiveInBackground": true,
  "encrypt": false,
  "usePluginSync": true,
  "usePluginSyncV2": true,
  "customChunkSize": 60,
  "handleFilenameCaseSensitive": false,
  "deviceAndVaultName": "server-headless-livesync"
}
```

## Verification

Write a test line on server:

```bash
echo "server test $(date -u +%H:%M:%S)" >> /srv/vault-write/TEST-LIVESYNC-FROM-ORACLE.md
```

Expected: it appears on mac and mobile without git commit.


---

## Minimal service shape

```ini
[Unit]
Description=Self-hosted LiveSync CLI Daemon
After=network-online.target

[Service]
Type=simple
WorkingDirectory=/opt/obsidian-livesync
ExecStart=/usr/bin/node dist/index.cjs /srv/livesync-db --vault /srv/vault-write daemon
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
```

Credentials belong in an environment file or local settings store, not in the public note.

For the full proposal and design decisions that led to this setup, see [unified-agent-memory-openspec-plan](/unified-agent-memory-openspec-plan.md).
