Guest - Testers are needed for the reworked CDateTime core component. See... https://forum.kodi.tv/showthread.php?tid=378981 (September 29) x
Linux Unable to access 'shutdown' & 'restart' options when starting Kodi from cron
#1
Hey, I've tried a few different attempts to solve this issue and I think I've hit a dead end. The machine I'm having these issues on is running an x86 version of Ubuntu server 22.04.2

My issue is simply that Kodi won't show the power off, reboot, hibernate and suspend options when clicking on the power menu when the process is started from a cron task (also when starting the process from ssh). Those options present themselves when I run Kodi from a normal shell; everything works as intended. The previous hardware I used Kodi for was a raspberry pi that never had this issue. From my understanding raspian has more included in the sudoers in order to make the sudo experience easier. I copied all of those into my new machine, however that didn't fix the issue. The user that runs the cron is in my understanding added to all the groups it should be in, I believe that lined up with raspian.

If an error log would be helpful, I can post it. After skimming it the only thing that caught my eye was this one line:
warning <general>: JSONRPC: Could not parse type "Setting.Details.SettingList"

I'm not quite sure what else to try, sorry if this isn't the right place to ask this question. Thank you for your time
Reply
#2
its a permissions issue from what it sounds like

i suspect youll find that kodi is running as different users in your various methods

read this - https://betterstack.com/community/questi...cific-user

in case youre not sure which user kodi is running as when "is working as expected" just use ps aux | grep kodi
Reply
#3
(2023-03-14, 17:45)jepsizofye Wrote: ps aux | grep kodi

Hey, thank you for the suggestion. I've been using crontab -e from the same user I log in as. Looking at ps aux shows Kodi from cron and tty are both from the same user, however there was a difference in process state codes. I don't think the '+' part is important but the 'L' implies it 'has pages locked into memory.' Alongside process state codes there was an additional process when started from cron. Unfortunately I'm not proficient enough to solve this problem given either of these leads.

The following link shows the differences from ps aux:
https://paste.kodi.tv/osuritomax
Reply
#4
the plus indicates the process is part of the foreground process group, the lack of indicates it is a background process

the lack of a tty is more interesting, im not sure if kodi has to have a tty to be able to function in that way

in your crontab try adding " &" to the end of the command line for kodi, it should separate the process and i think give it a tty

(that is a space and an ampersand)
Reply
#5
There was a difference when using the cront task "@reboot kodi &" unfortunately it didn't solve the issue. The results of ps aux look like this:
kodi        1037  0.0  0.0   2888   988 ?        S    04:25   0:00 /bin/sh /usr/bin/kodi
kodi        1043  8.7  1.6 2500284 227668 ?      Sl   04:25   0:02 /usr/lib/x86_64-linux-gnu/kodi/kodi.bin
There's one less process
Reply
#6
Okay, I found a solution without having to start Kodi as root, thanks to all the helpful posts on this link:
https://forum.kodi.tv/showthread.php?tid...=polIcykit

I'm not sure why it works when the equivalent file on Raspian doesn't need to be changed in such a manner.
If you go into /usr/share/polkit-1/actions/org.freedesktop.login1.policy and change the policies for "org.freedesktop.login1.reboot" "org.freedesktop.login1.power-off"  and "org.freedesktop.login1.hibernate"  from auth_admin_keep to yes you can use a @reboot Kodi crontask as a normal user and get those options to present themselves.

I'm going to guess there's a more elegant solution that eludes me, or that I overlooked/didn't understand. Either way I'm very grateful for this forum

I also should state this solution works with both Ubuntu 22.04.2 LTS and Debian 11.
Reply
#7
right on
Reply
#8
you're not supposed to edit files in /usr/, instead _create_ /etc/polkit-1/localauthority/50-local.d/custom-actions.pkla:
Code:
[Actions for kodi user]
Identity=unix-user:kodi
Action=org.freedesktop.login1.*;org.freedesktop.udisks2.*
ResultAny=yes
ResultInactive=yes
ResultActive=yes

[Untrusted Upgrade]
Identity=unix-user:kodi
Action=org.debian.apt.upgrade-packages;org.debian.apt.update-cache
ResultAny=yes
ResultInactive=yes
ResultActive=yes

make sure to adjust "unix-user" to the username you start kodi with
Reply
#9
Oh, thanks for the correction! I didn't know editing stuff in /usr was discouraged.

Would it be acceptable to add this information to a wiki page? There's currently a page, but seems to be intended for desktop versions of Linux, not for server versions.

I also should've said in my last post that this works with Ubuntu 22.04 (server) and Debian 11 without a DE.
Reply
#10
Having spent a long evening trying to sort this out after having installed Ubuntu 24.04 server (by default everyone has power management rights on the desktop version) the method above (using /etc/polkit-1/localauthority) no longer works

I solved it by creating a file /etc/polkit-1/rules.d/50-power.rules:
Code:
polkit.addRule(function(action, subject) {
    if ((action.id == "org.freedesktop.login1.reboot" ||
         action.id == "org.freedesktop.login1.reboot-multiple-sessions" ||
         action.id == "org.freedesktop.login1.power-off" ||
         action.id == "org.freedesktop.login1.power-off-multiple-sessions" ||
         action.id == "org.freedesktop.login1.suspend" ||
         action.id == "org.freedesktop.login1.suspend-multiple-sessions"))
    {
    return polkit.Result.YES;
    }
});

See https://bbs.archlinux.org/viewtopic.php?id=216161
Note -- in the code above, I never use the subject to limit which users can shut the system down.
Reply

Logout Mark Read Team Forum Stats Members Help
Unable to access 'shutdown' & 'restart' options when starting Kodi from cron0