mirror of
https://github.com/swaywm/sway.git
synced 2025-02-16 22:34:27 +00:00
Refactor and reword
parent
76dfc8e7c9
commit
1044d2fb4c
|
@ -1,12 +1,12 @@
|
|||
# Systemd --user manager integration
|
||||
## Managing user applications with systemd
|
||||
|
||||
On Linux distributions based on systemd, it can also be used to manage and supervise user services (the so called **--user** manager). Some general examples for services supervised by it are gpg-agent, pulseaudio, dbus, etc (more and more Gnome and KDE services). In the case of **sway**, such services may be waybar, swayidle, mako, and similar.
|
||||
On systemd based Linux distributions, systemd can be used as an alternative way to start and manage user services and applications. Some general examples of services managed by systemd include gpg-agent, pulseaudio, dbus, etc, but in the case of sway, such services may also include waybar, swayidle, mako, and similar. Note that this method works for both X11 and Wayland programs.
|
||||
|
||||
In order to enable this integration we need to configure a sway session target that will also bind to the standard [graphical-session.target](https://www.freedesktop.org/software/systemd/man/systemd.special.html#graphical-session.target) user target. Then, services can have `WantedBy=sway-session.target` or `WantedBy=graphical-session.target` to be started with either sway, or any graphical session (including Gnome or KDE)¹.
|
||||
In order to enable this integration, we need to configure a sway session target that will also bind to the standard [graphical-session.target](https://www.freedesktop.org/software/systemd/man/systemd.special.html#graphical-session.target) user target. This allows services to be started by systemd after sway launches by specifying `WantedBy=sway-session.target` or `WantedBy=graphical-session.target`.
|
||||
|
||||
To configure the sway session target, place the following systemd unit file either locally at `~/.config/systemd/user/sway-session.target`, or globally for all users at `/etc/systemd/user/sway-session.target`:
|
||||
|
||||
Here is the required sway-session.target unit, that must be placed either in `~/.config/systemd/user/sway-session.target` for the user, or globally in `/etc/systemd/user/sway-session.target` for all users (distributions would place it in /usr):
|
||||
```
|
||||
# ~/.config/systemd/user/sway-session.target or /etc/systemd/user/sway-session.target
|
||||
[Unit]
|
||||
Description=sway compositor session
|
||||
Documentation=man:systemd.special(7)
|
||||
|
@ -15,21 +15,25 @@ Wants=graphical-session-pre.target
|
|||
After=graphical-session-pre.target
|
||||
```
|
||||
|
||||
The next two lines should go to /etc/sway/config.d/10-systemd which is included in the default config or just pasted at the end of the users config itself. The idea is to import the sway environment variables into the systemd --user manager, and then start the `sway-session` user target:
|
||||
In order for the unit file to work properly, add the following lines to either `/etc/sway/config.d/10-systemd` which will include it in the default config, or add them to the end of the user's config file:
|
||||
|
||||
```
|
||||
# /etc/sway/config.d/10-systemd
|
||||
exec systemctl --user import-environment
|
||||
exec systemctl --user start sway-session.target
|
||||
```
|
||||
|
||||
So, when the user logs in via sddm or getty, the --user manager is automatically started (by pam_systemd and logind), and then when sway runs it will update the environment variables of the --user manager, and start the target, which will instruct systemd to start and supervise all the other services with the appropriate environment. You can have both wayland or X11 services started like this.
|
||||
The first line imports all environmental variables into the systemd user manager session which allows user services to access the variables. The second line starts the sway session user target.
|
||||
|
||||
To walkthrough the stages of how this works:
|
||||
- The user logs in via sddm or getty and the systemd user manager is automatically started (by pam_systemd and logind).
|
||||
- When sway is run, it will import the environment variables into the systemd user manager and start the sway session target.
|
||||
- The systemd user manager will then start all the services that depend on that target, and will provide them access to the imported env variables.
|
||||
|
||||
## Running sway itself as a --user service
|
||||
|
||||
Sway 1.0 supports running as a systemd --user service itself. The unit file is simple enough:
|
||||
Place the following unit file either at `~/.config/systemd/user/sway.service` or `/etc/systemd/user/sway.service`:
|
||||
|
||||
```
|
||||
# ~/.config/systemd/user/sway.service or /etc/systemd/user/sway.service
|
||||
[Unit]
|
||||
Description=sway - SirCmpwn's Wayland window manager
|
||||
Documentation=man:sway(5)
|
||||
|
@ -45,7 +49,6 @@ Restart=on-failure
|
|||
RestartSec=1
|
||||
TimeoutStopSec=10
|
||||
```
|
||||
again, you can choose to put it in `/etc/systemd/user/` or `~/.config/systemd/user/`.
|
||||
|
||||
This service file will load environment variables from `~/.config/sway/env`, a [KEY=VALUE file](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#EnvironmentFile=). That's a good place to put variables such as `_JAVA_AWT_WM_NONREPARENTING=1` or `CLUTTER_BACKEND=wayland` (note: no need for export there, that is not a shell file).
|
||||
|
||||
|
@ -69,7 +72,6 @@ exec systemctl --wait --user start sway.service
|
|||
|
||||
Next time you login via gdm/sddm just choose "sway-service", instead of just "sway".
|
||||
|
||||
|
||||
## Example service units for other programs
|
||||
|
||||
### waybar
|
||||
|
@ -93,7 +95,6 @@ and then enable and start it with `systemctl --user enable --now waybar.service`
|
|||
|
||||
If you want waybar to start for any graphical session, you could replace the `WantedBy=` directive with `WantedBy=graphical-session.target` before enabling it (although it might not make sense to use waybar with gnome or i3).
|
||||
|
||||
|
||||
### swayidle
|
||||
|
||||
```
|
||||
|
@ -114,7 +115,6 @@ ExecStart=/usr/bin/swayidle -w \
|
|||
WantedBy=sway-session.target
|
||||
```
|
||||
|
||||
|
||||
### mako
|
||||
|
||||
```
|
||||
|
@ -129,9 +129,4 @@ ExecStart=/usr/bin/mako
|
|||
|
||||
[Install]
|
||||
WantedBy=sway-session.target
|
||||
```
|
||||
|
||||
|
||||
## End notes
|
||||
|
||||
- ¹ Gnome and KDE might not have graphical-session.target integration on all distributions (yet)
|
||||
```
|
Loading…
Reference in a new issue