|
| 1 | +# sqlite-watcher installation guide |
| 2 | + |
| 3 | +This document walks through running the sqlite-watcher service on Linux, macOS, and Windows. The watcher process should run beside the `.sqlite` file so it can tail the WAL and expose change batches over the embedded gRPC API. |
| 4 | + |
| 5 | +All platforms share these basics: |
| 6 | + |
| 7 | +- Create a token file (default `~/.seren/sqlite-watcher/token`) with restrictive permissions (owner read/write only). |
| 8 | +- Choose a queue database path (default `~/.seren/sqlite-watcher/changes.db`). Ensure the parent directory is `0700` on Unix. |
| 9 | +- Run `sqlite-watcher serve --queue-db <path> --listen <endpoint> --token-file <file>` to start the gRPC service. Endpoints use the `unix:/path` or `tcp:host:port` syntax. |
| 10 | + |
| 11 | +## Linux (systemd) |
| 12 | + |
| 13 | +1. Install binaries: |
| 14 | + |
| 15 | + ```bash |
| 16 | + sudo install -m 0755 database-replicator /usr/local/bin/database-replicator |
| 17 | + sudo install -m 0755 sqlite-watcher /usr/local/bin/sqlite-watcher |
| 18 | + ``` |
| 19 | + |
| 20 | +2. Create token + queue directories: |
| 21 | + |
| 22 | + ```bash |
| 23 | + install -d -m 0700 ~/.seren/sqlite-watcher |
| 24 | + openssl rand -hex 32 > ~/.seren/sqlite-watcher/token |
| 25 | + ``` |
| 26 | + |
| 27 | +3. Create `/etc/systemd/system/sqlite-watcher.service`: |
| 28 | + |
| 29 | + ```ini |
| 30 | + [Unit] |
| 31 | + Description=sqlite-watcher for /srv/app.db |
| 32 | + After=network-online.target |
| 33 | + |
| 34 | + [Service] |
| 35 | + User=replicator |
| 36 | + ExecStart=/usr/local/bin/sqlite-watcher serve \ |
| 37 | + --queue-db /var/lib/sqlite-watcher/changes.db \ |
| 38 | + --listen unix:/run/sqlite-watcher.sock \ |
| 39 | + --token-file /home/replicator/.seren/sqlite-watcher/token |
| 40 | + Restart=on-failure |
| 41 | + |
| 42 | + [Install] |
| 43 | + WantedBy=multi-user.target |
| 44 | + ``` |
| 45 | + |
| 46 | +4. Enable/start: |
| 47 | + |
| 48 | + ```bash |
| 49 | + sudo systemctl daemon-reload |
| 50 | + sudo systemctl enable --now sqlite-watcher.service |
| 51 | + ``` |
| 52 | + |
| 53 | +## macOS (launchd) |
| 54 | + |
| 55 | +1. Copy binaries into `/usr/local/bin`. |
| 56 | +2. Save the following to `~/Library/LaunchAgents/com.seren.sqlite-watcher.plist`: |
| 57 | + |
| 58 | + ```xml |
| 59 | + <?xml version="1.0" encoding="UTF-8"?> |
| 60 | + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 61 | + <plist version="1.0"> |
| 62 | + <dict> |
| 63 | + <key>Label</key> |
| 64 | + <string>com.seren.sqlite-watcher</string> |
| 65 | + <key>ProgramArguments</key> |
| 66 | + <array> |
| 67 | + <string>/usr/local/bin/sqlite-watcher</string> |
| 68 | + <string>serve</string> |
| 69 | + <string>--queue-db</string> |
| 70 | + <string>/Users/you/.seren/sqlite-watcher/changes.db</string> |
| 71 | + <string>--listen</string> |
| 72 | + <string>unix:/Users/you/.seren/sqlite-watcher/watcher.sock</string> |
| 73 | + <string>--token-file</string> |
| 74 | + <string>/Users/you/.seren/sqlite-watcher/token</string> |
| 75 | + </array> |
| 76 | + <key>RunAtLoad</key> |
| 77 | + <true/> |
| 78 | + <key>KeepAlive</key> |
| 79 | + <true/> |
| 80 | + <key>StandardOutPath</key> |
| 81 | + <string>/Users/you/Library/Logs/sqlite-watcher.log</string> |
| 82 | + <key>StandardErrorPath</key> |
| 83 | + <string>/Users/you/Library/Logs/sqlite-watcher.log</string> |
| 84 | + </dict> |
| 85 | + </plist> |
| 86 | + ``` |
| 87 | + |
| 88 | +3. Load the agent: `launchctl load ~/Library/LaunchAgents/com.seren.sqlite-watcher.plist`. |
| 89 | + |
| 90 | +## Windows (Service) |
| 91 | + |
| 92 | +1. Copy `database-replicator.exe` and `sqlite-watcher.exe` to a directory on `%PATH%` (e.g. `C:\Program Files\Seren`). |
| 93 | +2. Create a token file under `%USERPROFILE%\.seren\sqlite-watcher\token`. |
| 94 | +3. Use the built-in `sc.exe` to install a service (or NSSM if you prefer a GUI): |
| 95 | + |
| 96 | + ```powershell |
| 97 | + sc.exe create sqlite-watcher binPath= "C:\Program Files\Seren\sqlite-watcher.exe serve --queue-db C:\data\sqlite-watcher\changes.db --listen tcp:127.0.0.1:6000 --token-file %USERPROFILE%\.seren\sqlite-watcher\token" start= auto |
| 98 | + ``` |
| 99 | + |
| 100 | +4. Start the service with `sc.exe start sqlite-watcher`. |
| 101 | + |
| 102 | +Remember to open the firewall only if the watcher must accept remote TCP connections. In most deployments, keep it bound to loopback or Unix sockets. |
| 103 | + |
| 104 | +## Running sync-sqlite on a schedule |
| 105 | + |
| 106 | +- Linux/macOS: use cron or systemd timers to run `database-replicator sync-sqlite ...` periodically. |
| 107 | +- Windows: create a Scheduled Task pointing at `database-replicator.exe sync-sqlite ...`. |
| 108 | + |
| 109 | +Consult the smoke test (`scripts/test-sqlite-delta.sh`) to see a minimal end-to-end example. |
0 commit comments