# Template service unit for borgstore REST server with socket activation. # # The instance name (%i) is the repo identifier, which must match a # borgstore@%i.socket unit and an environment file in /etc/borgstore/. # # Deploy: # cp borgstore@.service borgstore@.socket /etc/systemd/system/ # systemctl daemon-reload # systemctl enable --now borgstore@repo1.socket # # Connect (borg client, via nginx reverse proxy — see nginx-borgstore.conf): # borg -r http://backup.example.com/repos/borg/repo1/ repo-create ... [Unit] Description=BorgStore REST server (%i) Documentation=https://github.com/borgbackup/borgstore # Start after the socket unit activates us; also restart if socket is restarted Requires=borgstore@%i.socket After=borgstore@%i.socket [Service] Type=simple User=borgstore Group=borgstore # Credentials loaded from per-instance env file. # Minimum required: BORGSTORE_BACKEND, BORGSTORE_USERNAME, BORGSTORE_PASSWORD EnvironmentFile=/etc/borgstore/%i.env # No absolute path here: systemd looks the executable up in its search path, # which covers /usr/local/bin ("pip install" as root) as well as /usr/bin (a # distribution package). Use an absolute path for an install in a virtualenv. ExecStart=borgstore-server-rest \ --backend ${BORGSTORE_BACKEND} \ --username ${BORGSTORE_USERNAME} \ --password ${BORGSTORE_PASSWORD} \ --socket-activation # Kill the process after 30 s of idle (no open connections). # Systemd will restart it on the next connection via the socket unit. # Remove these two lines if you prefer the process to stay resident. TimeoutStopSec=30 KillMode=control-group Restart=on-failure RestartSec=5 # Harden the service NoNewPrivileges=true ProtectSystem=strict ProtectHome=true ReadWritePaths=/srv/borgstore PrivateTmp=true # No RuntimeDirectory=borgstore here: /run/borgstore/ is shared by the sockets # of all instances, and systemd removes a runtime directory (with all the # sockets in it) as soon as the one instance declaring it stops or fails. [Install] # Not enabled directly; the .socket unit triggers this. WantedBy=multi-user.target