|
2 | 2 |
|
3 | 3 | Sometimes it can be nice to have user-specific runit services. For example, you |
4 | 4 | might want to open an ssh tunnel as the current user, run a virtual machine, or |
5 | | -regularly run daemons on your behalf. The most common way to do this is to |
6 | | -create a system-level service that runs |
| 5 | +regularly run daemons on your behalf. |
| 6 | + |
| 7 | +## runsvdir |
| 8 | + |
| 9 | +The most basic way to do this is to create a system-level service that runs |
7 | 10 | [runsvdir(8)](https://man.voidlinux.org/runsvdir.8) as your user, in order to |
8 | | -start and monitor the services in a personal services directory. |
| 11 | +start and monitor the services in a personal services directory. This does have |
| 12 | +limitations and downsides, though, as per-user services are started at boot and |
| 13 | +do not have access to things like the user's graphical session or D-Bus session |
| 14 | +bus. |
9 | 15 |
|
10 | 16 | For example, you could create a service called `/etc/sv/runsvdir-<username>` |
11 | 17 | with the following `run` script, which should be executable: |
@@ -46,3 +52,48 @@ ok: run: gpg-agent: (pid 19818) 0s |
46 | 52 |
|
47 | 53 | It may be convenient to export the `SVDIR=~/service` variable in your shell |
48 | 54 | profile. |
| 55 | + |
| 56 | +## turnstile |
| 57 | + |
| 58 | +[Turnstile](https://github.com/chimera-linux/turnstile) supports running |
| 59 | +per-user services that start with the user session using either runit or |
| 60 | +[dinit(8)](https://man.voidlinux.org/man8/dinit.8). |
| 61 | + |
| 62 | +If using the runit service backend, user services should be placed in |
| 63 | +`~/.config/service/`. |
| 64 | + |
| 65 | +To ensure that a subset of services are started before login can proceed, these |
| 66 | +services can be listed in `~/.config/service/turnstile-ready/conf`, for example: |
| 67 | + |
| 68 | +``` |
| 69 | +core_services="dbus foo" |
| 70 | +``` |
| 71 | + |
| 72 | +The `turnstile-ready` service is created by turnstile on first login. |
| 73 | + |
| 74 | +To give user services access to important environment variables, |
| 75 | +[chpst(8)](https://man.voidlinux.org/chpst.8)'s envdir functionality can be |
| 76 | +used. Inside user services, the convenience variable `TURNSTILE_ENV_DIR` can be |
| 77 | +used to refer to this directory. |
| 78 | + |
| 79 | +To make a service aware of these variables, wrap the `exec` line with `chpst -e |
| 80 | +"$TURNSTILE_ENV_DIR"`: |
| 81 | + |
| 82 | +``` |
| 83 | +exec chpst -e "$TURNSTILE_ENV_DIR" foo |
| 84 | +``` |
| 85 | + |
| 86 | +The helper script `turnstile-update-runit-env` can be used to update variables |
| 87 | +in this shared envdir: |
| 88 | + |
| 89 | +``` |
| 90 | +$ turnstile-update-runit-env DISPLAY XAUTHORITY FOO=bar BAZ= |
| 91 | +``` |
| 92 | + |
| 93 | +To run the [D-Bus session bus](../session-management.md#d-bus) using a |
| 94 | +turnstile-managed user service: |
| 95 | + |
| 96 | +``` |
| 97 | +$ mkdir -p ~/.config/service/dbus |
| 98 | +$ ln -s /usr/share/examples/turnstile/dbus.run ~/.config/service/dbus/run |
| 99 | +``` |
0 commit comments