You are not logged in.

#1 2020-12-13 12:40:32

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,612
Website

systemd on shutdown loses data due to not honoring ExecStop=

If I call systemctl to shutdown or reboot, it does not honor kodi-x11.service's ExecStop line which results in an unclean exit of kodi and of data loss since kodi writes out some data when it exits:

ExecStop=/usr/bin/killall --user kodi --exact --wait kodi-x11

By contrast, calling systemctl to stop the service works as expected.  I suspect that systemd is using some more powerful level of kill to force the application to quit on a shutdown/reboot.  Is there a way to modify this behavior to honor the ExecStop= as defined in the service?

EDIT: The addition of a TimeoutStopSec=30 to the [Service] section has no effect.

Last edited by graysky (2020-12-13 13:51:28)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2020-12-13 14:34:25

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,771
Website

Re: systemd on shutdown loses data due to not honoring ExecStop=

graysky wrote:

Shouldn't that have a line in the [Install] section to specify the .target? For example:

[Install]
WantedBy=multi-user.target

Not sure if that Alias line is correct either but I might be wrong.

Offline

#3 2020-12-13 14:58:59

Ropid
Member
Registered: 2015-03-09
Posts: 1,069

Re: systemd on shutdown loses data due to not honoring ExecStop=

Maybe the problem is the X server exiting, and then the kodi program crashing because X is gone?

Offline

#4 2020-12-13 16:51:05

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,612
Website

Re: systemd on shutdown loses data due to not honoring ExecStop=

@Head - The systemd.service man page suggests WantedBy= believe under [Install]
@Ropid - Something is odd with it for sure.  As a test, I changed the ExecStop= to sleep for 20 s and added a 30 sec timeout.

...
ExecStop=/usr/bin/sleep 20s
TimeoutStopSec=30

When I called `systemctl reboot` it did honor the 20 seconds of sleep before rebooting the system.  I am uncertain how I can get systemd to behave as I want:  wait for the kodi executable to send a clean exit signal before considering the service exited.

Does anyone understand the differences with respect to this aspect of stopping a service as it relates to:

1) systemctl stop kodi-x11 (which behaves as expected)
2) systemctl reboot (which does not behave as expected)

Last edited by graysky (2020-12-13 16:52:14)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#5 2020-12-13 18:50:42

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,771
Website

Re: systemd on shutdown loses data due to not honoring ExecStop=

graysky wrote:

The systemd.service man page suggests WantedBy= believe under [Install]

Sorry but I don't understand what you mean by this hmm

Have you tried adding my suggested line to the [Install] section? The unit will have to be re-enabled to create the new symlink to /etc/systemd/system/multi-user.target.wants/.

Offline

#6 2020-12-13 19:34:56

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,612
Website

Re: systemd on shutdown loses data due to not honoring ExecStop=

@Head - My bad... misread that.  See: https://bbs.archlinux.org/viewtopic.php?pid=1131267

FYI - I did try your suggestion removing the alias line and subing in your line.  Reenabled and daemon-reloaded but same problem with systemd killing the service too quickly.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#7 2020-12-14 12:45:13

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,612
Website

Re: systemd on shutdown loses data due to not honoring ExecStop=

I posted to the systemd ML and Andrei was kind enough to reply.

Caused me to search 'systemd wait for user session on shutdown.'  Here are two relevant hits:

https://superuser.com/questions/1450650 … own-reboot
https://stackoverflow.com/questions/429 … -on-reboot

It seems that in order to avoid systemd killing my process running as the kodi user without waiting, I need to make certain that it isn't in the user.slice (traceable by running `systemd-cgls`.  Removing the PAMName=login seems to achieve this (as well removing systemd-user-sessions.service from After=).

That caused addition issues with a lack of kodi shutdown menu items but I think I can solve that with a polkit rule set.  Will do some testing and update the thread.

Last edited by graysky (2020-12-16 14:32:49)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#8 2020-12-14 13:01:45

gnumdk
Member
Registered: 2009-10-15
Posts: 175

Re: systemd on shutdown loses data due to not honoring ExecStop=

[Unit]
Description=Fermeture de session
DefaultDependencies=no
Conflicts=shutdown.target
Before=basic.target shutdown.target

[Service]
Type=oneshot
ExecStop=/usr/local/session/bin/session_close.sh
RemainAfterExit=yes
TimeoutStopSec=5m

[Install]
WantedBy=basic.target

Offline

Board footer

Powered by FluxBB