What happens on "Power off system" from "Power Options" menu?


when I shutdown the vero via “Power Options/Power off system”- what happens exactly?

The reason for the question is: I installed the “Home Cinema Automation” Addon, where I can send commands to my FHEM on certain events. One Event is named “On Shutdown”. When I stop the Vero using the menu, that command is NOT sent. But when I use “Power Options/Exit”, the command is sent!

I suspect that the shutdown is not done properly so that the addon is not able to send anything. All other events work like I would expect it.


I managed to get what I want by creating a systemd service. However, I think this should not be necessary, since that is a function that clearly the addon is providing.

I’m still interested in a solution without the systemd service.

My guess is that the add-on means “On Kodi exit” where it says “On Shutdown”. The “Power off system” menu command is just like typing “poweroff” on the SSH command line. It tells all services to stop, and it’s likely that Kodi doesn’t get the same message as if you select “Exit” from the menu.

This is because the actual service process is /usr/bin/mediacenter, which then runs /usr/lib/kodi/kodi.bin. I don’t see anything in either the service description file or the mediacenter shell script that handles signals in way that is “graceful” as far as Kodi is concerned. I supect that kodi.bin just gets a SIGTERM and exits without firing the event you are looking for.

Perhaps @sam_nazarko & Co. can modify the mediacenter.service so that signals can also fire off JSON messages to the Kodi webserver so that external shutdown requests turn into the same thing as “Exit” from the GUI.

Thanks nabsltd for the explanation. It would be interesting, how the “On Shutdown” is really meant. It doesn’t really make sense the way it is working now… And anybody without some systemd or general linux knowledge will have a hard time to use the feature.

Looking again at the /usr/bin/mediacenter script, it already traps SIGTERM, and waits for kodi.bin to exit.

The “trap” command parameter could be replaced by a function that does the same wait, but first sends the JSON command to Kodi. It still might not get through, as the OS might send SIGTERM to kodi.bin before this happens. I don’t know how to fix this timing issue.

I used to work with a system where I wrote a bash script that ran its functions in the background, and did its own job control to keep the number of child processes below a configured number. So, I know how ugly this sort of timing thing can be.

Also, the mediacenter script would have to check on startup to see if the Kodi webserver is enabled or not, and then skip sending the JSON if it is not.