Rework services and dependencies
systemd should not be viewed as a dependency manager but as an event manager (ie: sway should up the *.target witch should not be automatically pulled via dependency).
Also wayland-session*.target will not happen, I should use Condition*=
https://lwn.net/Articles/833247/
https://systemd.io/DESKTOP_ENVIRONMENTS/
sway.service should only bring up the *-session-pre.target and the *-session.target should be started via the config file. I need to figure-out the "cleanest" way to do it and how to bring it down when sway.service is stopping.
Hi, I've given this project a look, and I like the effort you put into standardizing this. Kudos🙂
I bumped into the problem described here as well. What if:
- In
sway.seeviceinstead ofBindsTo=sway-session.targetyou usePartOf=sway-session.target. - Remove
RefuseManualStart=yesfromsway-session.target. - In the config file add
&& systemctl --user start sway-session.target.
Edit
The above will not work as is, because sway-session.target has StopWhenUnneeded=yes. So right after everything is up, it's not needed anymore and stops, thus bringing everything down with it. So:
- Remove
StopWhenUnneeded=yesfromsway-session.target.
Now everything works correctly. Stopping sway-session.target will stop everything. However, stopping sway.service leaves sway-session.target (as well as graphical-session.target) running. Makes sense, nobody stops it. So make sway-session.target bind to sway.service. So sway.service is PartOf=sway-session.target (so that when sway-session.target stops, sway.service stops as well) and sway-session.target BindsTo=sway.service (so that when sway.service dies, sway-session.target stops as well). The latter makes logical sense too, i.e., you cannot have sway-session.target started without having sway.service started. So:
- Add
BindsTo=sway.servicetosway-session.target.
In the process of writing my own services, I got to the same conclusions as @alextsits wrote in 1. & 5.
Also, I don't see the point of having wayland-session* targets/services, as there already have sway-session* target/services and sway.service.
I named the Sway service sway-session.service.
I'm not sure about the combination of PartOf and Requires for the same target. The only difference I found after a quick test between this combination to BindsTo, is that the latter will also stop the unit if the one of the listed units entered inactive state. Is this needed if the listed unit is from the type target?
Instead, I'm using the combination of PartOf and Requisite.
Similarly to the suggestion of binding sway.service to sway-session.target, I also have the graphical-session.target bound to sway-session.target.
IMO it's not correct to ship it like this, so I'm making the change dynamically.
sway-session-pre.target
[Unit]
Description=Sway session services which should run early before the graphical session is brought up
PartOf=sway-session.target
Wants=graphical-session-pre.target sway-session-pre.service
Before=graphical-session-pre.target sway-session.target
sway-session-pre.service
[Unit]
Description=Sway compositor session setup
PartOf=sway-session-pre.target
Before=sway-session-pre.target
[Service]
Type=oneshot
RemainAfterExit=yes
StandardOutput=null
ExecStart=systemd-run --user --collect --pty --wait --service-type=oneshot --setenv=SYSTEMD_EDITOR=tee /bin/sh -c 'systemctl --user edit --runtime graphical-session.target <<EOF\n\
[Unit]\nBindsTo=sway-session.target\nEOF'
ExecStop=systemctl --user revert graphical-session.target