sway-services icon indicating copy to clipboard operation
sway-services copied to clipboard

Rework services and dependencies

Open xdbob opened this issue 5 years ago • 5 comments

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*=

xdbob avatar May 18 '20 06:05 xdbob

https://lwn.net/Articles/833247/

xdbob avatar Oct 05 '20 06:10 xdbob

https://systemd.io/DESKTOP_ENVIRONMENTS/

xdbob avatar Oct 09 '20 08:10 xdbob

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.

xdbob avatar Dec 26 '20 11:12 xdbob

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:

  1. In sway.seevice instead of BindsTo=sway-session.target you use PartOf=sway-session.target.
  2. Remove RefuseManualStart=yes from sway-session.target.
  3. 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:

  1. Remove StopWhenUnneeded=yes from sway-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:

  1. Add BindsTo=sway.service to sway-session.target.

alextsits avatar Jan 19 '22 10:01 alextsits

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

tinywrkb avatar Feb 02 '22 16:02 tinywrkb