Hello.
First, I’ve a Raspberry Pi 2 with OSMC RC.
I’m executing a script inside OSMC, from a custom main menu button action: RunScript(/home/osmc/myscript.py). This script will launch other application, but will close OSMC first, however nothing gets executed after I close OSMC.
My script looks like:
#!/usr/bin/python
import subprocess
subprocess.call('sudo sh /home/osmc/limelight/limelight.sh &', shell=True)
All I have in test.log is “before close” if launched inside osmc with RunScript (btw also tired System.Exec but can’t get that to even call the script).
Any ideia why this is happening?
You might wanna check out @mcobit’s post about using RetroPie with OSMC. His retropie.sh script will close Kodi and start EmulationStation. Once you close EmulationStation, Kodi restarts. Sounds like what you are trying to accomplish.
The only way I could accomplish that is to detach the closing command from shell with nohup and adding the starting of emulationstation into the custom mediacenter script as the stoppting of the service calls the mediacenter script and cleans up before exiting what closes the current tty apparently and your script will get closed, too.
So I use nohup amd openvt to get it running on a new virtualterminal. Sounds complicated and it is but I havent found another way.
Of course, if you find a better solution, let me know.
I would love to have a solution where it is not necessary to modify the mediacenter script as installing your application and the retropie script, with the same solution they would overwrite each other.
Maybe there could also be “launch other stuff” section that looks for userscripts to be executed on kodi quit in the mediacenter script in upstream OSMC. But that would need to be discussed with the main devs.
I wasn’t a big fan of modifying the mediacenter script mainly because of possible breakage due to OSMC updates. I also noticed that your install script didn’t make a “backup copy” of the mediacenter script, so I wound up doing that first, just in case.
Looking forward to see if you come up with another way.
You could get away with just one extra script when using nohup and in case of emulationstation openvt.
I only have ssh access to my pi until tomorrow so I cannot test this right now. But I will report back.
But maybe I can explain the main problem a bit in case someone else tries to figure it out before me:
When you start a script that opens another program and then stops the mediacenter service, the script started from KODI will also be terminated and therefore also your application.
After the mediacenter service is stopped it executes the mediacenter scipt again though with the parameter stop to clean up before a terminal session can be opened.
This is where I start my program and another script that watches the status of emulationstation in the background and restarts KODI if emulationstation quits with nohup and openvt right now by checking if a file exists that is created by me retropie.sh script.
Confused already?
Well. This is the only way I was able to keep the launched program alive until it is shut down.
If there is a way to let a launched program grab the input from KODI, it could just stay open in the background. That might introduce other problems though like still reacting to input or using up ressources.
I modified the script to run a script that I wrote myself, to throw from a menu item OSMC. But I have a problem at the time of launch, as my script requires one parameter and I am not able to find the solution.
# Start stream
sudo su osmc -c "nohup openvt -c 7 -s -f sh /home/limelight/stream.sh >/dev/null 2>&1 &" &
Using the example of @miko , how I can pass a parameter to “stream.sh” script? I’ve tried different way and do not receive it:
sudo su osmc -c "nohup openvt -c 7 -s -f 'sh /home/limelight/stream.sh -a 1' >/dev/null 2>&1 &" &
sudo su osmc -c "nohup openvt -c 7 -s -f -- sh /home/limelight/stream.sh -a 1 >/dev/null 2>&1 &" &
sudo su osmc -c "nohup openvt -c 7 -s -f "sh /home/limelight/stream.sh -a 1" >/dev/null 2>&1 &" &
Thank you very much, would greatly value your help.