| 1 | # Template service unit for borgstore REST server with socket activation. |
| 2 | # |
| 3 | # The instance name (%i) is the repo identifier, which must match a |
| 4 | # borgstore@%i.socket unit and an environment file in /etc/borgstore/. |
| 5 | # |
| 6 | # Deploy: |
| 7 | # cp [email protected] [email protected] /etc/systemd/system/ |
| 8 | # systemctl daemon-reload |
| 9 | # systemctl enable --now [email protected] |
| 10 | # |
| 11 | # Connect (borg client, via nginx reverse proxy — see nginx-borgstore.conf): |
| 12 | # borg -r http://backup.example.com/repos/borg/repo1/ repo-create ... |
| 13 | |
| 14 | [Unit] |
| 15 | Description=BorgStore REST server (%i) |
| 16 | Documentation=https://github.com/borgbackup/borgstore |
| 17 | # Start after the socket unit activates us; also restart if socket is restarted |
| 18 | Requires=borgstore@%i.socket |
| 19 | After=borgstore@%i.socket |
| 20 | |
| 21 | [Service] |
| 22 | Type=simple |
| 23 | User=borgstore |
| 24 | Group=borgstore |
| 25 | |
| 26 | # Credentials loaded from per-instance env file. |
| 27 | # Minimum required: BORGSTORE_BACKEND, BORGSTORE_USERNAME, BORGSTORE_PASSWORD |
| 28 | EnvironmentFile=/etc/borgstore/%i.env |
| 29 | |
| 30 | ExecStart=/usr/bin/borgstore-server-rest \ |
| 31 | --backend ${BORGSTORE_BACKEND} \ |
| 32 | --username ${BORGSTORE_USERNAME} \ |
| 33 | --password ${BORGSTORE_PASSWORD} \ |
| 34 | --socket-activation |
| 35 | |
| 36 | # Kill the process after 30 s of idle (no open connections). |
| 37 | # Systemd will restart it on the next connection via the socket unit. |
| 38 | # Remove these two lines if you prefer the process to stay resident. |
| 39 | TimeoutStopSec=30 |
| 40 | KillMode=control-group |
| 41 | |
| 42 | Restart=on-failure |
| 43 | RestartSec=5 |
| 44 | |
| 45 | # Harden the service |
| 46 | NoNewPrivileges=true |
| 47 | ProtectSystem=strict |
| 48 | ProtectHome=true |
| 49 | ReadWritePaths=/srv/borgstore |
| 50 | PrivateTmp=true |
| 51 | # Keep /run/borgstore/ alive for the lifetime of the service. |
| 52 | # The socket unit also declares RuntimeDirectory=borgstore, which creates |
| 53 | # the directory (with correct ownership) before the socket is bound. |
| 54 | RuntimeDirectory=borgstore |
| 55 | RuntimeDirectoryMode=0755 |
| 56 | |
| 57 | [Install] |
| 58 | # Not enabled directly; the .socket unit triggers this. |
| 59 | WantedBy=multi-user.target |