forge
Explore
Log in

Don't you dare go Hollow

Improve dinit service files (#3193)

Browse files at this commit

3bfa4a71ffb4457ce092454dfad6938f70028c28UnverifiedMark KarlinskyParent: 3158f5a
* Improve dinit service files and niri-session

Two main changes were made:
 - After a discussion in davmac314/dinit#496, 2 dinit services are now
   provided. The first one is 'niri', which runs niri itself, and the
   second one is 'niri.target' which brings up all the dependences from
   user configuration.
 - Made the behaviour of 'niri-session' when running under dinit closer
   to the behaviour when running under systemd. In particular, now the
   script wait for service completion, because some login managers shut
   the session down the moment the startup script completes.

* Update paths in docs
docs/wiki/Getting-Started.mdmodified+1 -1
@@ -223,7 +223,7 @@ This defaults to `/usr/bin/niri`.
223 | `resources/niri.service` (systemd) | `/etc/systemd/user/` |223 | `resources/niri.service` (systemd) | `/etc/systemd/user/` |
224 | `resources/niri-shutdown.target` (systemd) | `/etc/systemd/user/` |224 | `resources/niri-shutdown.target` (systemd) | `/etc/systemd/user/` |
225 | `resources/dinit/niri` (dinit) | `/etc/dinit.d/user/` |225 | `resources/dinit/niri` (dinit) | `/etc/dinit.d/user/` |
226-| `resources/dinit/niri-shutdown` (dinit) | `/etc/dinit.d/user/` |226+| `resources/dinit/niri.target` (dinit) | `/etc/dinit.d/user/` |
227 227
228 [Alacritty]: https://github.com/alacritty/alacritty228 [Alacritty]: https://github.com/alacritty/alacritty
229 [fuzzel]: https://codeberg.org/dnkl/fuzzel229 [fuzzel]: https://codeberg.org/dnkl/fuzzel
docs/wiki/Packaging-niri.mdmodified+1 -1
@@ -24,7 +24,7 @@ To do that, put files into the correct directories according to this table.
24 | `resources/niri.service` (systemd) | `/usr/lib/systemd/user/` |24 | `resources/niri.service` (systemd) | `/usr/lib/systemd/user/` |
25 | `resources/niri-shutdown.target` (systemd) | `/usr/lib/systemd/user/` |25 | `resources/niri-shutdown.target` (systemd) | `/usr/lib/systemd/user/` |
26 | `resources/dinit/niri` (dinit) | `/usr/lib/dinit.d/user/` |26 | `resources/dinit/niri` (dinit) | `/usr/lib/dinit.d/user/` |
27-| `resources/dinit/niri-shutdown` (dinit) | `/usr/lib/dinit.d/user/` |27+| `resources/dinit/niri.target` (dinit) | `/usr/lib/dinit.d/user/` |
28 28
29 Doing this will make niri appear in GDM and other display managers.29 Doing this will make niri appear in GDM and other display managers.
30 30
resources/dinit/nirimodified+7 -8
@@ -1,8 +1,7 @@
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
1+type = process
2+command = niri --session
3+restart = false
4+working-dir = $HOME
5+ready-notification = pipevar:NOTIFY_FD
6+logfile = $HOME/.local/share/niri/niri.log
7+depends-on: dbus
resources/dinit/niri-shutdowndeleted+0 -3
@@ -1,3 +0,0 @@
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/dinit/niri.targetadded+6 -0
@@ -0,0 +1,6 @@
1+type = internal
2+restart = false
3+depends-on: niri
4+waits-for.d: $XDG_CONFIG_HOME/dinit.d/niri.d/
5+waits-for.d: $HOME/.config/dinit.d/niri.d/
6+waits-for.d: /etc/dinit.d/user/niri.d/
resources/niri-sessionmodified+26 -2
@@ -59,13 +59,37 @@ elif hash dinitctl >/dev/null 2>&1; then
59 fi59 fi
60 60
61 # Make sure there's no already running session.61 # Make sure there's no already running session.
62- if dinitctl --user is-started niri >/dev/null 2>&1; then62+ if dinitctl --quiet --user is-started niri 2>/dev/null; then
63 echo 'A niri session is already running.'63 echo 'A niri session is already running.'
64 exit 164 exit 1
65 fi65 fi
66 66
67+ # Import the login manager environment into dinit
68+ # Might not work correctly for multiline variable names, but
69+ # it is reasonable to assume there are none
70+ awk 'BEGIN{for(v in ENVIRON) if (v != "AWKPATH" && v != "AWKLIBPATH") print v}' 2>/dev/null | xargs dinitctl --quiet --user setenv 2>/dev/null
71+
72+ # Usually the dbus service would start as niri's dependency and inherit
73+ # environment from dinit, but in case it has already started we need
74+ # to update its environment.
75+ if hash dbus-update-activation-environment >/dev/null 2>&1; then
76+ dbus-update-activation-environment --all >/dev/null 2>&1
77+ fi
78+
79+ # Create the directory for the logfile, if doesn't exist
80+ mkdir --parents $HOME/.local/share/niri
67 # Start niri81 # Start niri
68- dinitctl --user start niri82+ dinitctl --quiet --user start niri.target 2>&1
83+
84+ # Wait for termination
85+ dinit-monitor --user --initial -c $'sh -c "
86+ if [ "%s" = "stopped" ] || [ "%s" = "failed" ]; then
87+ ppid=$(ps -o ppid= -p $$)
88+ kill $ppid
89+ fi"' niri >/dev/null 2>&1
90+
91+ # Unset environment that we've set.
92+ dinitctl --quiet --user unsetenv WAYLAND_DISPLAY DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP NIRI_SOCKET 2>/dev/null
69 else93 else
70 echo "No systemd or dinit detected, please use niri --session instead."94 echo "No systemd or dinit detected, please use niri --session instead."
71 fi95 fi