xbianonpi / xbian

XBMC on Raspberry Pi, Bleeding Edge
https://xbian.org
GNU General Public License v3.0
294 stars 46 forks source link

Different Shutdown Behaviour between Console and Kodi #877

Closed pkoevesdi closed 4 years ago

pkoevesdi commented 4 years ago

I've already written this in the forum, but sadly no support there. After some own research I consider this a bug. Please correct me and explain, if I'm wrong.

I realized that there seem different shutdown routines whether I choose "shutdown" from the Kodi menu or do a sudo shutdown -h now from ssh. Shutdown scripts inside /etc/rc0.d/K... (symlinked to /etc/init.d/ by executing update-rc.d ...) get perfectly executed by a shutdown via sudo shutdown -h now, but not, when selected "Shutdown" from the Kodi menu. Also the messages showing below the progress bar are different between these two shutdown processes.

Using while true; do who -r;done show that the runlevels the system goes through are the same between these two ways of triggering a shutdown. One salience: On sudo shutdown -h now the output is:

...
         run-level 2  2020-04-26 07:40
         run-level 2  2020-04-26 07:40
         run-level 2  2020-04-26 07:40

Broadcast message from xbian@xbian
    (/dev/pts/3) at 10:23 ...

The system is going down for halt NOW!
         run-level 0  2020-04-26 10:23                   last=2
         run-level 0  2020-04-26 10:23                   last=2
         run-level 0  2020-04-26 10:23                   last=2
...

while after using the Kodi menu it is:

...
         run-level 2  2020-04-26 10:25
         run-level 2  2020-04-26 10:25
         run-level 2  2020-04-26 10:25
         run-level    2020-04-26 10:26
         run-level    2020-04-26 10:26
         run-level    2020-04-26 10:26
... 
         run-level    2020-04-26 10:26
         run-level    2020-04-26 10:26
         run-level    2020-04-26 10:26

Broadcast message from root@xbian
    (unknown) at 10:26 ...

The system is going down for power off NOW!
         run-level 0  2020-04-26 10:26
         run-level 0  2020-04-26 10:26
         run-level 0  2020-04-26 10:26
...

So, there's no direct transition between runlevels 2 and 0. And in runlevel 0, there's no "last runlevel" entry. That might prevent some shutdown scripts from running, since as far as I understood upstart prevents some script executions depending on the previous runlevel. I think, that mechanism is coded in /etc/init.d/rc. So, one question nis: why is the shutdown process out of kodi going into some undefined runlevel between 2 and 0?

Xbian 1.0 is running on Base of Debian 10. On my system the readings are:

xbian@xbian / $ cat /etc/os-release
PRETTY_NAME="XBian 1.0 (knockout)"
...
xbian@xbian / $ cat /etc/debian_version
10.3

Debian 10 is normally running with systemd as startup system. https://wiki.debian.org/Init But Xbian is using upstart:

xbian@xbian / $ /sbin/init --version
init (upstart 1.13.2)

Is that intentionally?

Next question: How come that, although using Upstart, the scripts in /lib/systemd/system-shutdown/ get executed anyway? Both when using sudo shutdown -h now or Kodi menu shutdown.

So, I consider a bug that there is no consistent way for having a script perform on startup and shutdown, either by sudo shutdown -h now or Kodi menu shutdown: The startup scripts in /etc/rc?.d/ work well, but the shutdown ones don't work via Kodi menu. The shutdown scripts inside /lib/systemd/system-shutdown/ work both ways, but that mechanism there doesn't provide a startup folder, does it?

pkoevesdi commented 4 years ago

Btw. the runlevel process is not essentially different whether I make sudo shutdown -h now (as user xbian) (see above) or make shutdown -P now (as user root and power off instead of halt, like Kodi does). The latter gives:

...
         run-level 2  2020-04-27 09:23
         run-level 2  2020-04-27 09:23
         run-level 2  2020-04-27 09:23

Broadcast message from root@xbian
    (/dev/pts/3) at 9:24 ...

The system is going down for power off NOW!
         run-level 0  2020-04-27 09:24                   last=2
         run-level 0  2020-04-27 09:24                   last=2
         run-level 0  2020-04-27 09:24                   last=2
...

While shutdown from Kodi, there's terminal "unknown" in the broadcast message, see above. Now I'll try the hints from http://forum.xbian.org/thread-4085-post-36579.html#pid36579

pkoevesdi commented 4 years ago

Ok, with the changes in /etc/init/elogind.conf proposed in http://forum.xbian.org/thread-4085-post-36579.html#pid36579 the process after shutdown from Kodi looks like this:

...
         run-level 2  2020-04-27 10:29
         run-level 2  2020-04-27 10:29
         run-level 2  2020-04-27 10:29

Broadcast message from root@xbian
    (unknown) at 10:30 ...

The system is going down for power off NOW!
         run-level 0  2020-04-27 10:30                   last=2
         run-level 0  2020-04-27 10:30                   last=2
         run-level 0  2020-04-27 10:30                   last=2
...

So, looks better, there's the expected direct transition from runlevel 2 to 0. (Still terminal "unknown", though, but that's probably not connected to this or any bug). And compelling, my script in /etc/init.d/ gets executed on shutdown from Kodi as well as expected. So far I cannot see any negative side effects, I'd suggest to make a pull request out of the change in /etc/init/elogind.conf. I rather leave that up to You. Thank You very much!!!