You are not logged in.

#1 2015-03-03 16:55:49

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,815
Website

Start a service before poweroff.target

I have created a service that saves a kde session

Now I want it to start it before poweroff.target so that when I issue systemctl poweroff it saves my kde session and then my system shuts down

I added kde-save-session.service dependencies to poweroff.target

[Unit]
Description=Power-Off
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-poweroff.service kde-save-session.service
After=systemd-poweroff.service 
Before=kde-save-session.service
AllowIsolate=yes   
JobTimeoutSec=30min
JobTimeoutAction=poweroff-force

But now when I issue systemctl poweroff I get this.

Failed to start poweroff.target: Transaction order is cyclic. See system logs for details.

journal:

Found ordering cycle on kde-save-session.service/start
Found dependency on poweroff.target/stop
Found dependency on systemd-poweroff.service/stop
Found dependency on shutdown.target/stop
Found dependency on kde-save-session.service/start
Unable to break cycle
Requested transaction contains an unfixable cyclic ordering dependency: Transaction order is cyclic. See system logs for details.

Any ideas what is going on here?


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#2 2015-03-03 17:13:22

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Start a service before poweroff.target

It may be a stupid question, but why? Isn't the easiest way to do this by using the KDE session manager? (And for startup, set up autologin and start x automatically)

Offline

#3 2015-03-03 17:23:37

ugjka
Member
From: Latvia
Registered: 2014-04-01
Posts: 1,815
Website

Re: Start a service before poweroff.target

At this point I don't even know why, but I just want to know if it is possible.
I'm curious what I'm doing wrong, I want to understand this black magic called systemd

Last edited by ugjka (2015-03-03 17:25:07)


https://ugjka.net
paru > yay | webcord > discord
pacman -S spotify-launcher
mount /dev/disk/by-...

Offline

#4 2015-03-03 18:16:13

nullified
Member
From: Massachusetts, USA
Registered: 2013-12-09
Posts: 468

Re: Start a service before poweroff.target

Is your kde-save-session.service exactly the same as in the post you linked to, or were any changes made? If it's the latter, please post that here as well.


"We may say most aptly, that the Analytical Engine weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." - Ada Lovelace

Offline

#5 2015-03-03 18:46:27

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Start a service before poweroff.target

ugjka wrote:

At this point I don't even know why, but I just want to know if it is possible.
I'm curious what I'm doing wrong, I want to understand this black magic called systemd

Ah ok. Well, read the documentation tongue

I think your problem is that poweroff.target both requires and is before kde-save-session.service. This would mean that if you go to poweroff, you want kde-save-session.service to be done, but you also want the target to be before kde-save-session.service. That is a cyclic dependency, don't you think?

(If I failed to understand the requires directive, please tell me so tongue)

Last edited by runical (2015-03-03 18:46:37)

Offline

#6 2015-03-03 18:56:51

nullified
Member
From: Massachusetts, USA
Registered: 2013-12-09
Posts: 468

Re: Start a service before poweroff.target

runical wrote:
ugjka wrote:

At this point I don't even know why, but I just want to know if it is possible.
I'm curious what I'm doing wrong, I want to understand this black magic called systemd

Ah ok. Well, read the documentation tongue

I think your problem is that poweroff.target both requires and is before kde-save-session.service. This would mean that if you go to poweroff, you want kde-save-session.service to be done, but you also want the target to be before kde-save-session.service. That is a cyclic dependency, don't you think?

(If I failed to understand the requires directive, please tell me so tongue)

The documentation for Requires= seems to say otherwise.

Note that requirement dependencies do not influence the order in which services are started or stopped.

So it should be okay that poweroff.target requires kde-save-session.service and is also loaded before it.

If that is true though, then I don't see why there is a cyclic dependency...


Edit: and from Before=, After=:

Note that this setting is independent of and orthogonal to the requirement dependencies as configured by Requires=.

Last edited by nullified (2015-03-03 18:58:23)


"We may say most aptly, that the Analytical Engine weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." - Ada Lovelace

Offline

#7 2015-03-03 19:02:09

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Start a service before poweroff.target

Hmm. Ok, thanks for the explanation. Seems I have some reading to do.

It is strange though. This would mean that the only way there can be a cyclic dependency is if kde-save-session.service requires poweroff.target.

Offline

#8 2015-03-03 19:40:50

nullified
Member
From: Massachusetts, USA
Registered: 2013-12-09
Posts: 468

Re: Start a service before poweroff.target

I asked the nice people in #systemd.

man systemd.service

and notice the bit about

DefaultDependencies

By default, this is set to true. You need to set it to false.

Unless DefaultDependencies is set to false, service units will implicitly have dependencies of type Requires= and After= on basic.target as well as dependencies of type Conflicts= and Before= on shutdown.target. These ensure that normal service units pull in basic system initialization, and are terminated cleanly prior to system shutdown. Only services involved with early boot or late system shutdown should disable this option.

This was a good learning experience, whether or not you actually use the service file!

The cycle was this:

  • poweroff.target requires systemd-poweroff.service and kde-save-session.service

  • systemd-poweroff.service requires shutdown.target

  • kde-save-session.service CONFLICTS with shutdown.target

  • Hence, poweroff.target both requires and conflicts with shutdown.target

Last edited by nullified (2015-03-03 20:13:01)


"We may say most aptly, that the Analytical Engine weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." - Ada Lovelace

Offline

#9 2015-03-03 21:37:02

MK13
Member
From: Germany
Registered: 2014-04-12
Posts: 80

Re: Start a service before poweroff.target

Offline

Board footer

Powered by FluxBB