I am working on my first Kodi addon and I have run into a snag that I am hoping you can assist with.
Currently during my development I have created a context menu addon that calls a bash script as follows…
sudo systemctl stop mediacenter
sudo systemctl start mediacenter
At some point the sleep “60” will be replaced with some other functions but at this point my problem is that
The mediacenter does properly shut down as the first line requests but it never restarts.
If I execute this script from putty it works as expected.
Is it possible that the bash script is terminating once the mediacenter is stopped when called from my context menu?
Any assistance to get me over this hump would be welcome.
I moved your post to a new thread, as the Wiki is meant to be used only for suggesting improvements.
If you are running this script from Kodi, be sure to start it in a process that will persist after Kodi exits! The best way would be to create a systemd unit which in turn runs your script and stops Kodi
That makes some sense. I am currently launching my Addon from a context menu in Kodi and am hoping to exit kodi, run a different application then restart kodi after the other application has completed. If you can point me to some resources to get me started with persistence and systemd that would be helpful.
Thanks for the great work with osmc.
Thank you for the links.
Are there any practical examples that I can use as a base. I understand at a macro sense what I need to do.
But I am not certain how to get started with a systemd unit. if I understand this correctly a systemd unit would act like an event that is initiated at boot time then I would raise this event to run my script from kodi, therefore it is outside of Kodi and will continue when Kodi exits. Correct?
osmc@osmc:~$ ls /etc/systemd/system/
bluetooth.service.d dbus-org.freedesktop.Avahi.service halt.target.wants reboot.target.wants sysinit.target.wants vnc.service
bluetooth.target.wants emergency.service.d multi-user.target.wants sockets.target.wants texturecache.service
dbus-org.bluez.service fake-hwclock.service.d poweroff.target.wants sshd.service texturecache.timer
/lib/systemd/system is a better choice for examples
Unfortunately I am not getting very far with this.
I am hoping for the following.
Launch a script using a context menu option (working)
Pass parameters to the same script using a context menu option (working)
exit OSMC (sudo systemctl stop mediacenter) (Working)
execute a new application (not working as script halts after mediacenter exits)
restart OSMC (sudo systemctl start mediacenter)
I understand that I need to use Systemd to spawn a new process once OSMC exits but there are no great examples on how to do this. I see examples on starting Systemd applications on startup but nothing that gives me a hint as to what to do next or in line with what I need. My questions are
- How do I create a Systemd service that will execute my script?
- How do I pass parameters to my systemd service so that it knows to execute my application with the necessary parameters?
Some practical examples of this would be helpful beyond the provided links.
Have a look at our manual update service:
To install updates we need to exit Kodi, install the updates, then restart Kodi.
The way we do it is to start the manual update service from within kodi by calling:
sudo systemctl start manual-update
From python. This starts the manual-update service. If you look at the script for that service one of the first things it does is stops Kodi with
sudo systemctl stop mediacenter
It then proceeds to install updates then at the end it starts Kodi again.
Because it is another service that is stopping Kodi this is decoupled from the calling script thus your script will not be terminated when Kodi stops.
After a quick look, this is exactly what i was hoping for. Thanks for pointing me in the right direction.
I will let you know how I make out with my first addon.
This was definitely the piece of the puzzle I needed to get my add-on working.
I have all the pieces now and it is working on my system. Now that I have it working is there a way to deploy all the files that are required for my add-on during the Add-on installation?
This would consist of my systemd files and bash script. My goal is to have users install the add-on and not have to worry about the background work to get the systemd files and scripts in the right place.