aboutsummaryrefslogtreecommitdiff
path: root/resources
diff options
context:
space:
mode:
authorMark Karlinsky <34838287+markK24@users.noreply.github.com>2024-10-13 15:26:16 +0300
committerGitHub <noreply@github.com>2024-10-13 12:26:16 +0000
commitd7156df8428cb9e6665a212e66c74bdb25842be8 (patch)
tree11c1cb62fb6b2b93432cb519ea45a17bf107b0ab /resources
parent33b39913c7121a6c7b112beb0e329c3e64e4f57a (diff)
downloadniri-d7156df8428cb9e6665a212e66c74bdb25842be8.tar.gz
niri-d7156df8428cb9e6665a212e66c74bdb25842be8.tar.bz2
niri-d7156df8428cb9e6665a212e66c74bdb25842be8.zip
Add support for running as a dinit service (#728)
* 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 --------- Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
Diffstat (limited to 'resources')
-rw-r--r--resources/dinit/niri8
-rw-r--r--resources/dinit/niri-shutdown3
-rwxr-xr-xresources/niri-session74
3 files changed, 58 insertions, 27 deletions
diff --git a/resources/dinit/niri b/resources/dinit/niri
new file mode 100644
index 00000000..b3807b90
--- /dev/null
+++ b/resources/dinit/niri
@@ -0,0 +1,8 @@
+type = process
+command = niri --session
+restart = false
+working-dir = $HOME
+depends-on = dbus
+after = niri-shutdown
+chain-to = niri-shutdown
+options: always-chain \ No newline at end of file
diff --git a/resources/dinit/niri-shutdown b/resources/dinit/niri-shutdown
new file mode 100644
index 00000000..d609a933
--- /dev/null
+++ b/resources/dinit/niri-shutdown
@@ -0,0 +1,3 @@
+type = scripted
+command = dinitctl -u setenv WAYLAND_DISPLAY= XDG_SESSION_TYPE= XDG_CURRENT_DESKTOP= NIRI_SOCKET=
+restart = false \ No newline at end of file
diff --git a/resources/niri-session b/resources/niri-session
index 9b0ef7ae..2fe31987 100755
--- a/resources/niri-session
+++ b/resources/niri-session
@@ -11,31 +11,51 @@ if [ -n "$SHELL" ] &&
fi
fi
-# Make sure there's no already running session.
-if systemctl --user -q is-active niri.service; then
- echo 'A niri session is already running.'
- exit 1
+# Try to detect the service manager that is being used
+if hash systemctl &> /dev/null; then
+ # Make sure there's no already running session.
+ if systemctl --user -q is-active niri.service; then
+ echo 'A niri session is already running.'
+ exit 1
+ fi
+
+ # Reset failed state of all user units.
+ systemctl --user reset-failed
+
+ # Import the login manager environment.
+ systemctl --user import-environment
+
+ # DBus activation environment is independent from systemd. While most of
+ # dbus-activated services are already using `SystemdService` directive, some
+ # still don't and thus we should set the dbus environment with a separate
+ # command.
+ if hash dbus-update-activation-environment 2>/dev/null; then
+ dbus-update-activation-environment --all
+ fi
+
+ # Start niri and wait for it to terminate.
+ systemctl --user --wait start niri.service
+
+ # Force stop of graphical-session.target.
+ systemctl --user start --job-mode=replace-irreversibly niri-shutdown.target
+
+ # Unset environment that we've set.
+ systemctl --user unset-environment WAYLAND_DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP NIRI_SOCKET
+elif hash dinitctl &> /dev/null; then
+ # Check that the user dinit daemon is running
+ if ! pgrep -u $(id -u) dinit &> /dev/null; then
+ echo "dinit user daemon is not running."
+ exit 1
+ fi
+
+ # Make sure there's no already running session.
+ if dinitctl --user is-started niri &> /dev/null; then
+ echo 'A niri session is already running.'
+ exit 1
+ fi
+
+ # Start niri
+ dinitctl --user start niri
+else
+ echo "No systemd or dinit detected, please use niri --session instead."
fi
-
-# Reset failed state of all user units.
-systemctl --user reset-failed
-
-# Import the login manager environment.
-systemctl --user import-environment
-
-# DBus activation environment is independent from systemd. While most of
-# dbus-activated services are already using `SystemdService` directive, some
-# still don't and thus we should set the dbus environment with a separate
-# command.
-if hash dbus-update-activation-environment 2>/dev/null; then
- dbus-update-activation-environment --all
-fi
-
-# Start niri and wait for it to terminate.
-systemctl --user --wait start niri.service
-
-# Force stop of graphical-session.target.
-systemctl --user start --job-mode=replace-irreversibly niri-shutdown.target
-
-# Unset environment that we've set.
-systemctl --user unset-environment WAYLAND_DISPLAY XDG_SESSION_TYPE XDG_CURRENT_DESKTOP NIRI_SOCKET