Update Example-systemd-Setup.md to use add-wants (#1710)
Browse files at this commit1 changed file +18 -17
- wiki/Example-systemd-Setup.md +18 -17
wiki/Example-systemd-Setup.mdmodified+18 -17
| @@ -2,24 +2,21 @@ When starting niri from a display manager like GDM, or otherwise through the `ni | |||
| 2 | This provides the necessary systemd integration to run programs like `mako` and services like `xdg-desktop-portal` bound to the graphical session. | 2 | This provides the necessary systemd integration to run programs like `mako` and services like `xdg-desktop-portal` bound to the graphical session. |
| 3 | 3 | ||
| 4 | Here's an example on how you might set up [`mako`](https://github.com/emersion/mako), [`waybar`](https://github.com/Alexays/Waybar), [`swaybg`](https://github.com/swaywm/swaybg) and [`swayidle`](https://github.com/swaywm/swayidle) to run as systemd services with niri. | 4 | Here's an example on how you might set up [`mako`](https://github.com/emersion/mako), [`waybar`](https://github.com/Alexays/Waybar), [`swaybg`](https://github.com/swaywm/swaybg) and [`swayidle`](https://github.com/swaywm/swayidle) to run as systemd services with niri. |
| 5 | -In contrast to [`spawn-at-startup`](./Configuration:-Miscellaneous.md#spawn-at-startup), this lets you easily monitor their status and output, and restart or reload them. | 5 | +Unlike [`spawn-at-startup`](./Configuration:-Miscellaneous.md#spawn-at-startup), this lets you easily monitor their status and output, and restart or reload them. |
| 6 | 6 | ||
| 7 | 1. Install them, i.e. `sudo dnf install mako waybar swaybg swayidle` | 7 | 1. Install them, i.e. `sudo dnf install mako waybar swaybg swayidle` |
| 8 | -2. Create a `niri.service.wants` folder: `mkdir -p ~/.config/systemd/user/niri.service.wants` | 8 | +2. `mako` and `waybar` provide systemd units out of the box, so you can simply add them to the niri session: |
| 9 | - | ||
| 10 | - This is a special systemd folder. | ||
| 11 | - Any services linked there will be started together with `niri.service` (which is a systemd unit used by niri when running as a session). | ||
| 12 | - | ||
| 13 | -3. `mako` and `waybar` provide systemd units out of the box, so you can simply symlink them into the `niri.service.wants` folder: | ||
| 14 | 9 | ||
| 15 | ``` | 10 | ``` |
| 16 | - ln -s /usr/lib/systemd/user/mako.service ~/.config/systemd/user/niri.service.wants/ | 11 | + systemctl --user add-wants niri.service mako.service |
| 17 | - ln -s /usr/lib/systemd/user/waybar.service ~/.config/systemd/user/niri.service.wants/ | 12 | + systemctl --user add-wants niri.service waybar.service |
| 18 | ``` | 13 | ``` |
| 19 | 14 | ||
| 20 | -4. `swaybg` does not provide a systemd unit, since you need to pass the background image as a command-line argument. | 15 | + This will create links in `~/.config/systemd/user/niri.service.wants/`, a special systemd folder for services that need to start together with `niri.service`. |
| 16 | + | ||
| 17 | +3. `swaybg` does not provide a systemd unit, since you need to pass the background image as a command-line argument. | ||
| 21 | So we will make our own. | 18 | So we will make our own. |
| 22 | - Put the following into `~/.config/systemd/user/swaybg.service`: | 19 | + Create `~/.config/systemd/user/swaybg.service` with the following contents: |
| 23 | 20 | ||
| 24 | ``` | 21 | ``` |
| 25 | [Unit] | 22 | [Unit] |
| @@ -37,13 +34,14 @@ In contrast to [`spawn-at-startup`](./Configuration:-Miscellaneous.md#spawn-at-s | |||
| 37 | 34 | ||
| 38 | After editing `swaybg.service`, run `systemctl --user daemon-reload` so systemd picks up the changes in the file. | 35 | After editing `swaybg.service`, run `systemctl --user daemon-reload` so systemd picks up the changes in the file. |
| 39 | 36 | ||
| 40 | - Now, also symlink this to `niri.service.wants`: | 37 | + Now, add it to the niri session: |
| 41 | 38 | ||
| 42 | ``` | 39 | ``` |
| 43 | - ln -s ~/.config/systemd/user/swaybg.service ~/.config/systemd/user/niri.service.wants/ | 40 | + systemctl --user add-wants niri.service swaybg.service |
| 44 | ``` | 41 | ``` |
| 45 | 42 | ||
| 46 | -5. `swayidle` similarly does not provide a service so we will also make our own. Put the following into `~/.config/systemd/user/swayidle.service`: | 43 | +4. `swayidle` similarly does not provide a service, so we will also make our own. |
| 44 | + Create `~/.config/systemd/user/swayidle.service` with the following contents: | ||
| 47 | 45 | ||
| 48 | ``` | 46 | ``` |
| 49 | [Unit] | 47 | [Unit] |
| @@ -56,20 +54,23 @@ In contrast to [`spawn-at-startup`](./Configuration:-Miscellaneous.md#spawn-at-s | |||
| 56 | Restart=on-failure | 54 | Restart=on-failure |
| 57 | ``` | 55 | ``` |
| 58 | 56 | ||
| 59 | - Then, run `systemctl --user daemon-reload` and symlink this file to `niri.service.wants`: | 57 | + Then, run `systemctl --user daemon-reload` and add it to the niri session: |
| 60 | 58 | ||
| 61 | ``` | 59 | ``` |
| 62 | - ln -s ~/.config/systemd/user/swayidle.service ~/.config/systemd/user/niri.service.wants/ | 60 | + systemctl --user add-wants niri.service swayidle.service |
| 63 | ``` | 61 | ``` |
| 64 | 62 | ||
| 65 | That's it! | 63 | That's it! |
| 66 | Now these three utilities will be started together with the niri session and stopped when it exits. | 64 | Now these three utilities will be started together with the niri session and stopped when it exits. |
| 67 | You can also restart them with a command like `systemctl --user restart waybar.service`, for example after editing their config files. | 65 | You can also restart them with a command like `systemctl --user restart waybar.service`, for example after editing their config files. |
| 68 | 66 | ||
| 67 | +To remove a service from niri startup, remove its symbolic link from `~/.config/systemd/user/niri.service.wants/`. | ||
| 68 | +Then, run `systemctl --user daemon-reload`. | ||
| 69 | + | ||
| 69 | ### Running Programs Across Logout | 70 | ### Running Programs Across Logout |
| 70 | 71 | ||
| 71 | When running niri as a session, exiting it (logging out) will kill all programs that you've started within. However, sometimes you want a program, like `tmux`, `dtach` or similar, to persist in this case. To do this, run it in a transient systemd scope: | 72 | When running niri as a session, exiting it (logging out) will kill all programs that you've started within. However, sometimes you want a program, like `tmux`, `dtach` or similar, to persist in this case. To do this, run it in a transient systemd scope: |
| 72 | 73 | ||
| 73 | ``` | 74 | ``` |
| 74 | systemd-run --user --scope tmux new-session | 75 | systemd-run --user --scope tmux new-session |
| 75 | -``` | ||
| \ No newline at end of file | \ No newline at end of file | ||
| 76 | +``` | ||