Hello,
I had some issues with IAGL and Kodi.
More precisely, Kodi wouldn't completely close and the applaunch.sh process inherited the 9777 UDP port (kodi remote control port) because it is launched from Kodi, even if Kodi itself already exited.
So restarting Kodi would trigger an error about the Remote control service (because the port 9777 was already open by the bash process).
I have a solution though: instead of exiting Kodi and restarting it, I suspend and resume Kodi processes.
Here is my modified $HOME/.kodi/addons/plugin.program.iagl/resources/bin/applaunch.sh (I stripped everything not Linux, but feel free to improve and adapt it):
php:
#!/usr/bin/bash
# App Launch script - Exit Kodi to launch another program
# Updated by zachmorris for use with IAGL
# This script will try to exit Kodi first via JSONRPC, then a normal shutdown if the first attempt fails, then a hard shutdown if the second attempt fails
LOGFILE=$HOME/.config/retroarch/log.txt
# Check for agruments
if [ -z "$*" ]; then
echo "No arguments provided." >> $LOGFILE
echo "Usage:" >> $LOGFILE
echo "applaunch.sh [/path/to/]executable [arguments]" >> $LOGFILE
exit
fi
JSON_RPC_NOTIFICATION=$(curl -s --data-binary '{"jsonrpc": "2.0", "method": "GUI.ShowNotification", "params": {"title": "Please Wait", "message": "Running IAGL Launch Script" }, "id":1}' -H 'content-type: application/json;' --user myuser:mypassword http://127.0.0.1:8080/jsonrpc) >> $LOGFILE
KODI_PID_LINUX_X11=$(ps -A | grep [k]odi-x11 | head -1 | awk '{print $1}')
KODI_PID_LINUX=$(ps -A | grep [k]odi | head -1 | awk '{print $1}')
echo "KODI_PID_LINUX_X11 = $KODI_PID_LINUX_X11" >> $LOGFILE
echo "KODI_PID_LINUX = $KODI_PID_LINUX" >> $LOGFILE
#Sleep to let Kodi write to log
sleep 1
#Suspend Kodi
if ! [ -z $KODI_PID_LINUX_X11 ]
then
echo "Suspending Kodi..." >> $LOGFILE
kill -STOP $KODI_PID_LINUX_X11
kill -STOP $KODI_PID_LINUX
echo "Kodi suspended!" >> $LOGFILE
fi
#End Suspend Kodi
# Start Emulator Launch
echo "Launching Emulator with command: $@" >> $LOGFILE
# Launch app - escaped!
"$@" &
EMULATOR_PID=$!
echo "Waiting for emulator to exit..." >> $LOGFILE
wait $EMULATOR_PID
echo "Resuming Kodi..." >> $LOGFILE
sleep 2
kill -CONT $KODI_PID_LINUX_X11
kill -CONT $KODI_PID_LINUX
echo "Kodi resumed!" >> $LOGFILE
#End of script
Advantages :
- Kodi does not need to close and still does not use any CPU while suspended, so emulators can run at full speed
- Remote control service is still available after Kodi is resumed