Updated Systemd integration (markdown)

Дамјан Георгиевски 2019-02-05 23:36:01 +01:00
parent a79200892b
commit 7171209083

@ -6,6 +6,7 @@ In order to enable this integration we need to configure a sway session target t
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)
@ -20,7 +21,51 @@ 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.
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.
## Running sway itself as a --user service
Sway 1.0 supports running as a systemd --user service itself. The unit file is simple enough:
```
# ~/.config/systemd/user/sway.service or /etc/systemd/user/sway.service
[Unit]
Description=sway - SirCmpwn's Wayland window manager
Documentation=man:sway(5)
Before=graphical-session.service
Wants=graphical-session-pre.service
After=graphical-session-pre.service
[Service]
Type=simple
EnvironmentFile=-%h/.config/sway/env
ExecStart=/usr/bin/sway
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]).
Now, you want your login manager to start the service via systemd, and not sway directly. In order to do that, it's easiest to just create a new wayland session in `/usr/share/wayland-sessions/sway-session.desktop`:
```
[Desktop Entry]
Name=Sway Service
Comment=SirCmpwn's Wayland window manager as a systemd service
Exec=sway-service.sh
Type=Application
```
and put the sway-service.sh somewhere on your PATH (`/usr/local/bin/sway-service.sh` should be fine):
```
#! /bin/sh
# first import environment variables from the login manager
systemctl --user import-environment
# then start the service
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
@ -86,5 +131,4 @@ WantedBy=sway-session.target
## End notes
- ¹ Gnome and KDE might not have graphical-session.target integration on all distributions
- ² sway is not supervised by the --user manager yet
- ¹ Gnome and KDE might not have graphical-session.target integration on all distributions (yet)