forge
Explore
Log in

Don't you dare go Hollow

Add support for running as a dinit service (#728)

Browse files at this commit

d7156df8428cb9e6665a212e66c74bdb25842be8UnverifiedMark Karlinsky and Ivan MolodetskikhParent: 33b3991
* Added dinit services

* Added dinit support to niri-session

* Replaced shutdown script for dinit with a single command execution

* Added dinit service files to Getting Started install tables

* Fix typo in resources/dinit/niri

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>

* Fixed mistakes in wiki/Getting-Started.md

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>

* niri-session does not start dinit anymore

---------
resources/dinit/niriadded+8 -0
@@ -0,0 +1,8 @@
1+type = process
2+command = niri --session
3+restart = false
4+working-dir = $HOME
5+depends-on = dbus
6+after = niri-shutdown
7+chain-to = niri-shutdown
8+options: always-chain
\ No newline at end of file\ No newline at end of file
resources/dinit/niri-shutdownadded+3 -0
@@ -0,0 +1,3 @@
1+type = scripted
2+command = dinitctl -u setenv WAYLAND_DISPLAY= XDG_SESSION_TYPE= XDG_CURRENT_DESKTOP= NIRI_SOCKET=
3+restart = false
\ No newline at end of file\ No newline at end of file
resources/niri-sessionmodified+47 -27
@@ -11,31 +11,51 @@ if [ -n "$SHELL" ] &&
11 fi11 fi
12 fi12 fi
13 13
14-# Make sure there's no already running session.14+# Try to detect the service manager that is being used
15-if systemctl --user -q is-active niri.service; then15+if hash systemctl &> /dev/null; then
16- echo 'A niri session is already running.'16+ # Make sure there's no already running session.
17- exit 117+ if systemctl --user -q is-active niri.service; then
18+ echo 'A niri session is already running.'
19+ exit 1
20+ fi
21+
22+ # Reset failed state of all user units.
23+ systemctl --user reset-failed
24+
25+ # Import the login manager environment.
26+ systemctl --user import-environment
27+
28+ # DBus activation environment is independent from systemd. While most of
29+ # dbus-activated services are already using `SystemdService` directive, some
30+ # still don't and thus we should set the dbus environment with a separate
31+ # command.
32+ if hash dbus-update-activation-environment 2>/dev/null; then
33+ dbus-update-activation-environment --all
34+ fi
35+
36+ # Start niri and wait for it to terminate.
37+ systemctl --user --wait start niri.service
38+
39+ # Force stop of graphical-session.target.
40+ systemctl --user start --job-mode=replace-irreversibly niri-shutdown.target
41+
42+ # Unset environment that we've set.
43+ systemctl --user unset-environment WAYLAND_DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP NIRI_SOCKET
44+elif hash dinitctl &> /dev/null; then
45+ # Check that the user dinit daemon is running
46+ if ! pgrep -u $(id -u) dinit &> /dev/null; then
47+ echo "dinit user daemon is not running."
48+ exit 1
49+ fi
50+
51+ # Make sure there's no already running session.
52+ if dinitctl --user is-started niri &> /dev/null; then
53+ echo 'A niri session is already running.'
54+ exit 1
55+ fi
56+
57+ # Start niri
58+ dinitctl --user start niri
59+else
60+ echo "No systemd or dinit detected, please use niri --session instead."
18 fi61 fi
19-
20-# Reset failed state of all user units.
21-systemctl --user reset-failed
22-
23-# Import the login manager environment.
24-systemctl --user import-environment
25-
26-# DBus activation environment is independent from systemd. While most of
27-# dbus-activated services are already using `SystemdService` directive, some
28-# still don't and thus we should set the dbus environment with a separate
29-# command.
30-if hash dbus-update-activation-environment 2>/dev/null; then
31- dbus-update-activation-environment --all
32-fi
33-
34-# Start niri and wait for it to terminate.
35-systemctl --user --wait start niri.service
36-
37-# Force stop of graphical-session.target.
38-systemctl --user start --job-mode=replace-irreversibly niri-shutdown.target
39-
40-# Unset environment that we've set.
41-systemctl --user unset-environment WAYLAND_DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP NIRI_SOCKET
wiki/Getting-Started.mdmodified+10 -6
@@ -8,8 +8,8 @@ After installing, start niri from your display manager like GDM.
8 Press <kbd>Super</kbd><kbd>T</kbd> to run a terminal ([Alacritty]) and <kbd>Super</kbd><kbd>D</kbd> to run an application launcher ([fuzzel]).8 Press <kbd>Super</kbd><kbd>T</kbd> to run a terminal ([Alacritty]) and <kbd>Super</kbd><kbd>D</kbd> to run an application launcher ([fuzzel]).
9 To exit niri, press <kbd>Super</kbd><kbd>Shift</kbd><kbd>E</kbd>.9 To exit niri, press <kbd>Super</kbd><kbd>Shift</kbd><kbd>E</kbd>.
10 10
11-If you're not using a display manager, you should run `niri-session` (systemd) or `niri --session` (not systemd) from a TTY.11+If you're not using a display manager, you should run `niri-session` (systemd/dinit) or `niri --session` (others) from a TTY.
12-The `--session` flag will make niri import its environment variables globally into systemd and D-Bus, and start its D-Bus services.12+The `--session` flag will make niri import its environment variables globally into the system manager and D-Bus, and start its D-Bus services.
13 13
14 You can also run `niri` inside an existing desktop session.14 You can also run `niri` inside an existing desktop session.
15 Then it will open as a window, where you can give it a try.15 Then it will open as a window, where you can give it a try.
@@ -178,8 +178,10 @@ To do that, put files into the correct directories according to this table.
178 | `resources/niri-session` | `/usr/bin/` |178 | `resources/niri-session` | `/usr/bin/` |
179 | `resources/niri.desktop` | `/usr/share/wayland-sessions/` |179 | `resources/niri.desktop` | `/usr/share/wayland-sessions/` |
180 | `resources/niri-portals.conf` | `/usr/share/xdg-desktop-portal/` |180 | `resources/niri-portals.conf` | `/usr/share/xdg-desktop-portal/` |
181-| `resources/niri.service` | `/usr/lib/systemd/user/` |181+| `resources/niri.service` (systemd) | `/usr/lib/systemd/user/` |
182-| `resources/niri-shutdown.target` | `/usr/lib/systemd/user/` |182+| `resources/niri-shutdown.target` (systemd) | `/usr/lib/systemd/user/` |
183+| `resources/dinit/niri` (dinit) | `/usr/lib/dinit.d/user/` |
184+| `resources/dinit/niri-shutdown` (dinit) | `/usr/lib/dinit.d/user/` |
183 185
184 Doing this will make niri appear in GDM and other display managers.186 Doing this will make niri appear in GDM and other display managers.
185 187
@@ -195,8 +197,10 @@ These may vary depending on your distribution.
195 | `resources/niri-session` | `/usr/local/bin/` |197 | `resources/niri-session` | `/usr/local/bin/` |
196 | `resources/niri.desktop` | `/usr/local/share/wayland-sessions/` |198 | `resources/niri.desktop` | `/usr/local/share/wayland-sessions/` |
197 | `resources/niri-portals.conf` | `/usr/local/share/xdg-desktop-portal/` |199 | `resources/niri-portals.conf` | `/usr/local/share/xdg-desktop-portal/` |
198-| `resources/niri.service` | `/etc/systemd/user/` |200+| `resources/niri.service` (systemd) | `/etc/systemd/user/` |
199-| `resources/niri-shutdown.target` | `/etc/systemd/user/` |201+| `resources/niri-shutdown.target` (systemd) | `/etc/systemd/user/` |
202+| `resources/dinit/niri` (dinit) | `/etc/dinit.d/user/` |
203+| `resources/dinit/niri-shutdown` (dinit) | `/etc/dinit.d/user/` |
200 204
201 [Alacritty]: https://github.com/alacritty/alacritty205 [Alacritty]: https://github.com/alacritty/alacritty
202 [fuzzel]: https://codeberg.org/dnkl/fuzzel206 [fuzzel]: https://codeberg.org/dnkl/fuzzel