git-annex/doc/tips/Systemd_unit.mdwn

104 lines
2.5 KiB
Text
Raw Normal View History

2016-11-08 10:10:12 +00:00
---
---
/!\ __THIS PAGE IS A DRAFT__ /!\
---
---
## Introduction
Systemd is a suite of tools for system and user daemon management.
It can be used as an alternative to XDG autostart files to start the git-annex daemon and optionally the webapp, either at startup (system service) or when an user logs in (user service).
---
##Setup
2016-11-10 06:34:44 +00:00
### User service
2016-11-08 10:10:12 +00:00
2016-11-10 06:34:44 +00:00
Sample unit file (`/etc/systemd/user/git-annex.service`):
2016-11-08 10:10:12 +00:00
```
[Unit]
Description=git-annex assistant daemon
[Service]
2016-11-10 06:34:44 +00:00
ExecStart=/usr/bin/git-annex assistant --autostart --foreground
2016-11-08 10:10:12 +00:00
Restart=on-failure
[Install]
2016-11-10 06:34:44 +00:00
WantedBy=default.target
2016-11-08 10:10:12 +00:00
```
2016-11-10 06:34:44 +00:00
Commands for enabling and starting the service as the current user:
2016-11-08 10:10:12 +00:00
```
2016-11-10 06:34:44 +00:00
systemctl --user enable git-annex.service
systemctl --user start git-annex.service
2016-11-08 10:10:12 +00:00
```
2016-11-10 06:34:44 +00:00
Usually services in `default.target` start during login. (Note however that they also _delay_ the login process.) However, if you enable "linger" via `loginctl`, then these services start on boot instead.
2016-11-08 10:10:12 +00:00
2016-11-10 06:34:44 +00:00
### System service
2016-11-08 10:10:12 +00:00
2016-11-10 06:34:44 +00:00
If for some reason you cannot use `systemd --user`, the other option is to have system-wide services:
Sample unit file (`/etc/systemd/system/git-annex@.service`):
2016-11-08 10:10:12 +00:00
```
[Unit]
Description=git-annex assistant daemon
2016-11-10 06:34:44 +00:00
After=network.target
2016-11-08 10:10:12 +00:00
[Service]
2016-11-10 06:34:44 +00:00
User=%i
ExecStart=/usr/bin/git-annex assistant --autostart --foreground
2016-11-08 10:10:12 +00:00
Restart=on-failure
[Install]
2016-11-10 06:34:44 +00:00
WantedBy=multi-user.target
2016-11-08 10:10:12 +00:00
```
2016-11-10 06:34:44 +00:00
Commands for enabling and starting the service as user `u`:
2016-11-08 10:10:12 +00:00
```
2016-11-10 06:34:44 +00:00
systemctl enable git-annex@u.service
systemctl start git-annex@u.service
2016-11-08 10:10:12 +00:00
```
---
## Considerations
### Webapp
The webapp may be started instead of the assistant, by launching the associated command in the unit file. This will run an associated assistant automatically. However, it may also attempt to open a potentially unwanted browser window.
```
ExecStart=git-annex webapp
```
_TODO: try this._
### Encrypted home directory
Users may store their keyring and repositories in their encrypted home directory mounted at login. This may break a system service running at boot.
_TODO: try this._
### Common daemon
One daemon may be used to sync repositories for multiple users. For this, it might be helpful to make use of ACLs to access other user directories.
---
## References
- [systemd.unit man page](https://www.freedesktop.org/software/systemd/man/systemd.unit.html)
- [systemd on ArchWiki](https://wiki.archlinux.org/index.php/Systemd)
- [TL;DR Syncthing with systemd documentation](https://docs.syncthing.net/users/autostart.html#using-systemd)
- [Syncthing systemd unit files](https://github.com/syncthing/syncthing/tree/master/etc/linux-systemd)