Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework services and dependencies #12

Open
xdbob opened this issue May 18, 2020 · 5 comments
Open

Rework services and dependencies #12

xdbob opened this issue May 18, 2020 · 5 comments

Comments

@xdbob
Copy link
Owner

xdbob commented May 18, 2020

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
Copy link
Owner Author

xdbob commented Oct 5, 2020

@xdbob
Copy link
Owner Author

xdbob commented Oct 9, 2020

@xdbob
Copy link
Owner Author

xdbob commented Dec 26, 2020

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.

@alextsits
Copy link

alextsits commented Jan 19, 2022

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.

@tinywrkb
Copy link

tinywrkb commented Feb 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants