Forum
Different Shutdown process from Kodi or ssh - Printable Version

+- Forum (http://forum.xbian.org)
+-- Forum: Software (/forum-6.html)
+--- Forum: Configuration (/forum-17.html)
+--- Thread: Different Shutdown process from Kodi or ssh (/thread-4085.html)



Different Shutdown process from Kodi or ssh - Gauner - 24th Apr, 2020 04:14 AM

HEy,

I realize that there seem different shutdown routines whether I choose "shutdown" from the Kodi menu or do a "sudo shutdown - now" from ssh.
One thing I described here:
http://forum.xbian.org/thread-4084.html (different things showing below the progress bar).

Another thing I'm struggling with now is:
I have a shutdown script inside /etc/rc0.d/K... (spawned from /etc/init.d/ by executing update-rc.d ...). It gets perfectly executed when I do a "sudo shutdown -h now", but not, when I select "Shutdown" from the Kodi menu.

Is there an explanation for this? What's the difference between these processes? Can I make Kodi to execute excatly the same as "sudo shutdown -h now" from the shutdown menu?


RE: Different Shutdown process from Kodi or ssh - Gauner - 26th Apr, 2020 12:39 AM

Ok, I figured at least something out:
XBian uses the upstart mechanism for booting, right?
Terminal
xbian@xbian / $ /sbin/init --version
init (upstart 1.13.2)
and
Terminal
xbian@xbian / $ systemctl status
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
tell me so.
Terminal
xbian@xbian / $ sudo shutdown -h now
executes the scripts I put in /etc/init.d/ and symlinked in /etc/rc?.d/. These folders also belong to the upstart- / System-V-system. But they don#t get executed when shutdown from Kodi (I also check whether the passed parameter is different - it isn't, they don#t get executed at all).
On the other hand, scripts inside /lib/systemd/system-shutdown/ get executed as well, also if I shutdown from inside Kodi. This folder belongs to the systemd-System.

So, I ask: Is Kodi using systemd, while the rest of Xbian uses upstart? Is this a bug?


RE: Different Shutdown process from Kodi or ssh - Gauner - 26th Apr, 2020 04:19 AM

So, after all I read, Xbian 1.0 is running on Base of Debian 10.
Debian 10 is running with systemd as startup system.
Why is (at least my) Xbian using upstart?
Is that intentionally? Is there something wrong with my installation?
Can this be switched? Would it work?
How come that, although using UPSTART, the scripts in /lib/systemd/system-shutdown/ get executed?


RE: Different Shutdown process from Kodi or ssh - Nachteule - 26th Apr, 2020 11:37 PM

That's right, XBian ist based on Debian, but XBian requires Upstart due to historical reasons and this can not changed in the near future, probably never because of a couple of upstart features are used which does systemd not provide

There is nothing wrong with your installation

The scripts inside of /lib/systemd/system-shutdown/ are executed from /etc/init/progress-shutdown.conf and has nothing to do with systemd

Actually, Kodi is using the logind functionality (if it is there) to shutdown/reboot system. logind is provided by systemd or by alternative logind manager such as elogind that we use. It seems that there is the bug that shutdown from Kodi does not work as expected.

Atm, I have no idea how to fix it, maybe integrating shutdown tool will be a good aproach, will have to look deeper if this could work


RE: Different Shutdown process from Kodi or ssh - Gauner - 27th Apr, 2020 03:29 AM

Ok, thank you very much for clarification.
I already opened a issue on github.
I added there my finding about the different ways that the system changes the runlevel when shutdown from Kodi.

Is there a similar folder like /lib/systemd/system-shutdown that executes scripts at startup? Or is my consideration correct, that startup scripts must go into the rc?.d or rc.local, while shutdown scripts go into /lib/systemd/system-shutdown? So, there's no consistent way of executing a script on startup and shutdown?


RE: Different Shutdown process from Kodi or ssh - Nachteule - 27th Apr, 2020 05:09 AM

(27th Apr, 2020 03:29 AM)Gauner Wrote:  Ok, thank you very much for clarification.
I already opened a issue on github.
I added there my finding about the different ways that the system changes the runlevel when shutdown from Kodi.

Is there a similar folder like /lib/systemd/system-shutdown that executes scripts at startup? Or is my consideration correct, that startup scripts must go into the rc?.d or rc.local, while shutdown scripts go into /lib/systemd/system-shutdown? So, there's no consistent way of executing a script on startup and shutdown?

I've already seen you issue on github

I looked deeper into today and it seems that elogind is the culprit. Can't say if the version is too old (its the version shipped with buster, on giithub are oc newer versions matching with systemd versioning), or if just elogind is wrong configured.

Anyway, I have a test installation running without elogind, using logind from systemd, looks ok so far. Shutdown from Kodi works as expected (AFAIS)

I don't know if there is a startup folder similar to shutdown folder, I would assume there isn't though. And yes, I think you're right to put startup script into rc.local if required or look into file /etc/default/xbmc, variable USERRUN. maybe you can wrote your own userrun script

For a quick test, you can replace /etc/init/elogind.conf with
Code:
description "Enable user and session management by systemd/(e)logind"
author      "mkreisl mkreisl@xbian.org"

env EDAEMON=/lib/elogind/elogind
env SDAEMON=/lib/systemd/systemd-logind

start on started dbus and remote-filesystems
stop on starting rc RUNLEVEL=[06]

respawn

script
    if [ -e $SDAEMON ]; then
        DAEMON=$SDAEMON
    elif [ -e $EAEMON ]; then
        DAEMON=$EDAEMON
    fi
    test -e $DAEMON && exec $DAEMON || { stop; exit 0; }
end script

and install systemd (/lib/systemd/systemd-logind is provided by systemd)


RE: Different Shutdown process from Kodi or ssh - Gauner - 29th Apr, 2020 01:23 AM

This solution solves it, my shut down scripts get executed now! Thank You very much!