I found a solution for the OSMC start/stop issue using openvt & nohup. Thanks to mkobit for the OSMC/RetroPie scripts (GitHub - mcobit/retropie-osmc: This is a simple script to install retropie alongside osmc.).
First we need to install kdb & libopus-dev:
apt-get update
apt-get install kbd
apt-get install libopus-dev
Code of my scripts:
/home/limelight/limelight.sh:
#!/bin/sh
sudo openvt -c 7 -s -f clear
sudo openvt -c 7 -s -f echo "Running limelight from KODI"
# Start watchdog
sudo su osmc -c "sh /home/limelight/limelight_watchdog.sh &" &
# Start stream
sudo su osmc -c "nohup openvt -c 7 -s -f sh /home/limelight/stream.sh >/dev/null 2>&1 &" &
sudo openvt -c 7 -s -f clear
sleep 2
# Stop mediacenter
sudo su -c "systemctl stop mediacenter &" &
exit
/home/limelight/stream.sh:
sudo /sbin/modprobe snd-bcm2835
sudo java -jar /home/limelight/limelight.jar pair 192.168.x.x
sudo java -jar /home/limelight/limelight.jar stream 192.168.x.x -1080 -30fps
/home/limelight/limelight-watchdog.sh:
#!/bin/bash
sleep 60
while [ true ]; do
VAR1="$(pgrep java)"
if [ ! "$VAR1" ]; then
sudo openvt -c 7 -s -f clear
sudo openvt -c 7 -s -f echo "Limelight quit... Starting KODI."
sleep 1
sudo openvt -c 7 -f clear
sudo su -c "sudo systemctl restart mediacenter &" &
sleep 1
exit
else
sleep 2
fi
done
In OSMC just set a shortcut to “System.Exec(/home/limelight/limelight.sh)”.
Enjoy!