This script uses the kodi-send tool to prevent Kodi from shutting down if there are active SSH, SAMBA, or NFS connections. The script checks every 60 seconds, and if at least one connection exists the command InhibitIdleShutdown(true) is sent to Kodi.
Create /storage/.config/prevent_idle.sh with the following content:
#!/bin/sh
IDLE_SHUTDOWN_ALLOWED_LAST_STATE=-1
while true
do
KODI_RUNNING=`ps -A | grep kodi.bin | grep -v grep | wc -l`
if [ 1 == $KODI_RUNNING ] ; then
SSH_ACTIVE=`netstat -tnpa | grep 'tcp.*:22.*ESTABLISHED.*' | wc -l`
NFS_ACTIVE=`netstat -tnpa | grep 'tcp.*:111.*ESTABLISHED.*' | wc -l`
SMB_ACTIVE=`netstat -tnpa | grep 'tcp.*:445.*ESTABLISHED.*' | wc -l`
[ $SSH_ACTIVE -gt 0 -o $NFS_ACTIVE -gt 0 -o $SMB_ACTIVE -gt 0 ] && IDLE_SHUTDOWN_ALLOWED=1 || IDLE_SHUTDOWN_ALLOWED=0
if [ $IDLE_SHUTDOWN_ALLOWED_LAST_STATE != $IDLE_SHUTDOWN_ALLOWED ] ; then
IDLE_SHUTDOWN_ALLOWED_LAST_STATE=$IDLE_SHUTDOWN_ALLOWED
kodi-send --action="AllowIdleShutdown"
if [ 0 == $IDLE_SHUTDOWN_ALLOWED ] ; then
kodi-send --action="InhibitIdleShutdown(false)"
else
kodi-send --action="InhibitIdleShutdown(true)"
fi
fi
fi
sleep 60
done
Call the script from /storage/.config/autostart.sh so it runs as a background task. It will continue to monitor the state of connections until the device is halted.
Call the script from /storage/.config/autostart.sh so it runs as a background task. It will continue to monitor the state of connections until the device is halted.