Solved When does guisettings.xml get updated with new <systemtotaluptime> values?
#1
I noticed that the value for <systemtotaluptime> stored in ~/.kodi/userdata/guisettings.xml does not change despite constant uptime.  I stopped kodi, manually defined 0 as the value and started kodi and indeed, it remains constant.  Am I missing a system dependency needed to have this stored?

EDIT AFTER MARKING AS SOLVED: turns out my kodi.serivce was killing kodi-x11 before kodi-x11 could write out the updates to such as saving settings and other house keeping tasks.  For reference and as an example, here is what the kodi.log should look like when kodi is allowed to exit cleanly:
Code:
2020-10-25 07:14:56.393 T:139827912097600  NOTICE: Quitting due to POSIX signal
2020-10-25 07:14:56.433 T:139827912097600  NOTICE: Stopping player
2020-10-25 07:14:56.433 T:139827912097600  NOTICE: Storing total System Uptime
2020-10-25 07:14:56.433 T:139827912097600  NOTICE: Saving settings
2020-10-25 07:14:56.434 T:139827912097600  NOTICE: Saving skin settings
2020-10-25 07:14:56.435 T:139827912097600  NOTICE: Stopping all
2020-10-25 07:14:56.435 T:139827912097600  NOTICE: ES: Stopping event server
2020-10-25 07:14:56.435 T:139827912097600  NOTICE: CWebServer[8080]: Stopped
2020-10-25 07:14:57.212 T:139826846213696  NOTICE: ES: UDP Event server stopped
2020-10-25 07:14:57.480 T:139827912097600  NOTICE: Application stopped
2020-10-25 07:14:57.680 T:139827912097600  NOTICE: XBApplicationEx: destroying...
2020-10-25 07:14:57.746 T:139827912097600  NOTICE: unload skin
2020-10-25 07:14:57.758 T:139827912097600 WARNING: Cleanup: Having to cleanup texture lists/focus.png
2020-10-25 07:14:57.774 T:139827912097600  NOTICE: unload sections
2020-10-25 07:14:57.844 T:139827912097600  NOTICE: XBApplicationEx: application stopped!
Need help programming a Streamzap remote?
Reply
#2
guisettings.xml gets updated when Kodi exits.
Learning Linux the hard way !!
Reply
#3
@black_eagle - Thanks... I see what's going on.  I am running kodi from kodi-x11.service and allowing systemctl to stop it.  The pkill line must kill kodi and either not trigger it to write out that file or must kill kodi before it is able to write it out.  I will experiment with an ExecStop= that allows it.  I am thinking a call to kodi-send -a Quit but am open to suggestions that would avoid the need of the extra dependency of kodi-send.

EDIT: it seems that I need a sleep or else systemd kills kodi too quickly to write out the file, but a 1 sec delay seems to give the desired behavior.  I see LE is using a call to /bin/kill -TERM ... I will experiment with that.
Need help programming a Streamzap remote?
Reply
#4
Kodi gets the signal, will store the request to quit. The slow process loop (500 ms time based) will pick it up, that means in worst case 1s later and here quite is then issued, which needs a bit more time as well.

I'd only send the KILL if 10 seconds did pass, which you can easily do with systemd.

SIGINT or SIGTERM do both the same.
First decide what functions / features you expect from a system. Then decide for the hardware. Don't waste your money on crap.
Reply
#5
(2020-10-19, 00:15)fritsch Wrote: Kodi gets the signal, will store the request to quit. The slow process loop (500 ms time based) will pick it up, that means in worst case 1s later and here quite is then issued, which needs a bit more time as well.

I'd only send the KILL if 10 seconds did pass, which you can easily do with systemd.

SIGINT or SIGTERM do both the same.

Thanks for the info.  Do you have a suggested kodi.service to allow for:
1) sending SIGTERM to the kodi-x11 PID when systemd is called to exit and
2) If 10 s expires, sending the KILL
Need help programming a Streamzap remote?
Reply
#6
Thats what I use:
Code:
[Unit]
Description=Kodi
Requires=dbus.service
Wants=network-online.target
After=pulseaudio.service
After=polkit.service
After=network-online.target

[Service]
EnvironmentFile=/etc/default/kodi
User=kodi
Group=kodi
PAMName=systemd-user
StandardOutput=journal
StandardError=journal
ExecStart=/usr/lib/kodi/kodi.bin -fs --standalone
TimeoutStopSec=30
Restart=always
RestartSec=2
SuccessExitStatus=0 64 66
RestartPreventExitStatus=64 66
StartLimitInterval=0
LimitNOFILE=16384

[Install]
WantedBy=multi-user.target

Adapt to suit your needs, I use system pulseaudio with kodi (for bluetooth headphones only),
/etc/default/kodi contains relevant env var such as DISPLAY, etc
Systemd by default sends SIGTERM , no need to specify it.
TimeoutStopSec=30 will kill kodi with actual SIGKILL if service did not stop in 30s.

Edit this has been working well for years and survived many updates and hardware upgrades ) :
Code:
grep totaluptime guisettings.xml 
        <systemtotaluptime>844523</systemtotaluptime>
Reply
#7
@asavah - Thanks for sharing that... in my case, I am using kodi-x11.  Not sure what kodi.bin is on your end... gbm?
Need help programming a Streamzap remote?
Reply
#8
x11
Reply
#9
Are you running an Xserver with a separate service?

Can you post:
Code:
cat /etc/default/kodi

When I tried to run your service adapting my StartExec= I got the following:
Code:
Oct 20 15:54:17 myth2 systemd[1]: Started Kodi.
Oct 20 15:54:17 myth2 systemd[1626]: pam_systemd_home(systemd-user:account): systemd-homed is not available: Unit dbus-org.freedesktop.home1.service not found.
Oct 20 15:54:17 myth2 systemd[1626]: pam_warn(systemd-user:setcred): function=[pam_sm_setcred] flags=0x8002 service=[systemd-user] terminal=[] user=[kodi] ruser=[<unknown>] rhost=[<unknown>]
Oct 20 15:54:17 myth2 systemd[1626]: pam_unix(systemd-user:session): session opened for user kodi(uid=989) by (uid=0)
Oct 20 15:54:17 myth2 systemd[1626]: pam_systemd(systemd-user:session): Failed to stat() runtime directory '/run/user/989': No such file or directory
Oct 20 15:54:17 myth2 systemd[1626]: pam_systemd(systemd-user:session): Not setting $XDG_RUNTIME_DIR, as the directory is not in order.

The kodi.log seems to indicate a failure to start the X server:
Code:
...
2020-10-20 15:54:59.357 T:140274998026048   ERROR: X11 Error: No Display found
2020-10-20 15:54:59.357 T:140274998026048   FATAL: CApplication::Create: Unable to init windowing system
...
Need help programming a Streamzap remote?
Reply
#10
(2020-10-20, 16:33)asavah Wrote: /etc/default/kodi contains relevant env var such as DISPLAY, etc
Code:
DISPLAY=:0
JAVA_HOME=/usr/lib/jvm/java-8-openjdk
KODI_AE_SINK=PULSE
HOME=/home/kodi
XDG_CACHE_HOME=/home/kodi/.cache
DVDCSS_CACHE=/home/kodi/.cache/dvdcss
MALLOC_MMAP_THRESHOLD_=524288

You would need to add proper systemd unit dependencies too.
Like:
Code:
After=systemd-logind.service
After=systemd-user-sessions.service
[email protected]
[email protected]
Requires=whateverwindowmanageryouhave.service
Requires=xorg-or-whatever-you-name-it.service

I run xorg and openbox as separate services, not listed in my unit because I have another self-written daemon which manages "frontends" such as Kodi, Retroarch etc. via systemd dbus api and can be controlled via a remote or http api.
Xorg is launched via https://github.com/ahkok/xorg-launch-helper , I find it's the best approach because it's a "notify" type service, which allows me to start openbox when X server is actually ready,
otherwise when using xinit I stumbled into input issues.
I provided my unit as an example for TimeoutStopSec=30 .
I don't know your system and your goals so I can't provide units that'd work out of the box in your setup.
Reply
#11
Thanks for the info.  The goal is to have a kodi-x11.service basically to just run kodi-x11.  The point of the box is just to run kodi.
Need help programming a Streamzap remote?
Reply
#12
To close the loop on this, killall offers switches to allow systemd to wait for kodi to exit before killing it.  Below is my current kodi-x11.service.  Other service file for gbm and wayland as well as systemd user and tmp files can be found on my github repo for kodi-standalone-service.

Code:
[Unit]
Description=Kodi standalone (X11)
After=remote-fs.target systemd-user-sessions.service network-online.target nss-lookup.target sound.target bluetooth.target polkit.service upower.service mysqld.service
Wants=network-online.target polkit.service upower.service
[email protected]
[Service]
User=kodi
Group=kodi
EnvironmentFile=-/etc/conf.d/kodi-standalone
PAMName=login
TTYPath=/dev/tty1
Environment=WINDOWING=x11
ExecStart=/usr/bin/xinit /usr/lib/kodi/kodi-x11 --standalone -- :0 -quiet -nolisten tcp vt1
ExecStop=/usr/bin/killall --user kodi --exact --wait kodi-x11
Restart=on-abort
StandardInput=tty
StandardOutput=journal
[Install]
Alias=display-manager.service
Need help programming a Streamzap remote?
Reply

Logout Mark Read Team Forum Stats Members Help
When does guisettings.xml get updated with new <systemtotaluptime> values?0