| 1 | # borgstore systemd + nginx setup |
| 2 | |
| 3 | Runs one borgstore REST server per repository, started **on demand** by systemd |
| 4 | socket activation, with nginx terminating TLS and routing clients to the right |
| 5 | instance by URL path. |
| 6 | |
| 7 | ## How it works |
| 8 | |
| 9 | ``` |
| 10 | borg client |
| 11 | → http://backup.example.com/repos/myrepo/ (nginx) |
| 12 | → strips /repos/myrepo prefix |
| 13 | → http://unix:/run/borgstore/myrepo.sock:/ (borgstore process) |
| 14 | ``` |
| 15 | |
| 16 | Note: The example nginx configuration uses HTTP for simplicity and CI |
| 17 | compatibility. For production use, you **must** add SSL/TLS configuration. |
| 18 | |
| 19 | - **`[email protected]`** — systemd creates `/run/borgstore/<name>.sock` and |
| 20 | starts the matching service on the first incoming connection. |
| 21 | - **`[email protected]`** — runs `borgstore-server-rest --socket-activation`, |
| 22 | adopting the pre-bound socket from systemd. |
| 23 | - **`nginx-borgstore.conf`** — a single wildcard `location` block routes any |
| 24 | `/repos/<name>/` URL to the matching Unix socket; nginx strips the path |
| 25 | prefix so borgstore always sees requests rooted at `/`. |
| 26 | - **`borgstore-proxy.conf`** — shared nginx snippet (proxy headers, buffering |
| 27 | off, timeouts) included by the wildcard location. |
| 28 | |
| 29 | ## Files |
| 30 | |
| 31 | | File | Install to | |
| 32 | |------|------------| |
| 33 | | `[email protected]` | `/etc/systemd/system/` | |
| 34 | | `[email protected]` | `/etc/systemd/system/` | |
| 35 | | `nginx-borgstore.conf` | `/etc/nginx/sites-available/` | |
| 36 | | `borgstore-proxy.conf` | `/etc/nginx/snippets/` | |
| 37 | | `repo1.env.example` | `/etc/borgstore/<name>.env` (one per repo) | |
| 38 | |
| 39 | ## Adding a repository |
| 40 | |
| 41 | **1. Create the env file** (`chmod 600`, owned by `borgstore`): |
| 42 | |
| 43 | ```ini |
| 44 | # /etc/borgstore/myrepo.env |
| 45 | BORGSTORE_BACKEND=file:///srv/borgstore/myrepo |
| 46 | BORGSTORE_USERNAME=myuser |
| 47 | BORGSTORE_PASSWORD=secret |
| 48 | ``` |
| 49 | |
| 50 | **2. Enable the socket unit:** |
| 51 | |
| 52 | ```bash |
| 53 | systemctl enable --now [email protected] |
| 54 | ``` |
| 55 | |
| 56 | That's it. The wildcard nginx location picks up the new repo automatically |
| 57 | — no nginx reload needed. |
| 58 | |
| 59 | **3. Use with borg:** |
| 60 | |
| 61 | ```bash |
| 62 | borg -r http://myuser:[email protected]/repos/myrepo/ repo-create ... |
| 63 | ``` |
| 64 | |
| 65 | ## Initial deployment |
| 66 | |
| 67 | ```bash |
| 68 | # Install units |
| 69 | cp [email protected] [email protected] /etc/systemd/system/ |
| 70 | systemctl daemon-reload |
| 71 | |
| 72 | # Install nginx config |
| 73 | cp nginx-borgstore.conf /etc/nginx/sites-available/borgstore |
| 74 | ln -s /etc/nginx/sites-available/borgstore /etc/nginx/sites-enabled/ |
| 75 | cp borgstore-proxy.conf /etc/nginx/snippets/ |
| 76 | |
| 77 | # Create the borgstore system user (if not already present) |
| 78 | useradd --system --home /srv/borgstore --shell /usr/sbin/nologin borgstore |
| 79 | |
| 80 | # Add repos as above, then test nginx config |
| 81 | nginx -t && nginx -s reload |
| 82 | ``` |
| 83 | |
| 84 | ## Notes |
| 85 | |
| 86 | - The borgstore process is started on the first connection and stays running |
| 87 | while connections are open. Add `TimeoutStopSec=` to the service unit to |
| 88 | shut it down after a period of inactivity. |
| 89 | - The socket file at `/run/borgstore/<name>.sock` is recreated automatically |
| 90 | after a reboot by systemd (`RuntimeDirectory=borgstore` in the service unit). |
| 91 | - TLS is handled entirely by nginx; the borgstore process never sees HTTPS. |