Solved xbmc-send resets idle timer -> no shutdown
#1
Brick 
I currently have problems with automatic idle shutdown in XBMC
I set the timer in xbmc to shutdown after 15 min.
Additionally I run a cron-script every 5 min to check if
  • smb/nfs shares are used
  • PVR (mythtv) is active
  • SSH-users are logged on
  • packets are being installed (synaptic).
At the end the script performs from shell (depending on shutdown allowed or not):
Code:
xbmc-send --action="XBMC.AllowIdleShutdown"
or
Code:
xbmc-send --action="XBMC.InhibitIdleShutdown"
My problem is, that xbmc-send seems to reset the idle time. I have an addon service.watchedlist that becomes active if it detects user action (idle timer decreases, checking xbmc.getGlobalIdleTime() ).
Is there any workaround other than setting the cron-script-intervall greater than the xbmc shutdown idle timer?
Setting both timers to 5min worked, but I want timeouts like mentioned above.

There seem to be two opinions on how to call xbmc-send with idleshutdown: with true/false argument (http://forum.xbmc.org/showthread.php?tid=171659) or without (http://wiki.xbmc.org/index.php?title=Lis..._functions).
Reply
#2
(2013-09-05, 09:29)schapplm Wrote: There seem to be two opinions on how to call xbmc-send with idleshutdown: with true/false argument (http://forum.xbmc.org/showthread.php?tid=171659) or without (http://wiki.xbmc.org/index.php?title=Lis..._functions).

You can issue the xbmc-send command manually from a terminal session and then checking the shutdown menu to see if the option changes from "Inhibit idle shutdown" to "Allow idle shutdown" and vice versa to determine which version actually works. Smile
Reply
#3
Quote:You can issue the xbmc-send command manually from a terminal session and then checking the shutdown menu to see if the option changes from "Inhibit idle shutdown" to "Allow idle shutdown" and vice versa to determine which version actually works.
Ok it took me some time to figure out, that the option inhibit/allow shutdown is not available in the Aeon Nox skin but in Confluence.
It seems you have to use true/false, like in Confluence Source Code.
Code:
xbmc-send --action="XBMC.InhibitIdleShutdown(true/false)"
The other option XBMC.AllowIdleShutdown from http://wiki.xbmc.org/index.php?title=XBM...ing_Manual did not work.

Now only the second problem remains: Every use of xbmc-send seems to set the idle timer to zero. Has anyone experience with this behaviour?
Edit: I forgot to mention that i use XBMC 12.2 Frodo on Ubuntu 12.04.3 LTS.
Reply
#4
I believe that's normal.
Reply
#5
Ok thank you. I will try and arrange with this by setting the timers somehow. Realized now, that this was a toppic a few days earlier. http://forum.xbmc.org/showthread.php?tid=171659.

Closed.
Reply
#6
I changed the cron-script so that it should work now:

/usr/bin/idleshutdown_cron.sh
Code:
#!/bin/bash
# cron-Script to shutdown the machine if all programs are idle (xmbc and mythtv backend)
# xmbc-send will reset the xbmc idle timer. So XBMC.InhibitIdleShutdown(false) must only be send if this is a new state.
#
# source:
# http://forum.xbmc.org/showthread.php?tid=171659
# http://forum.xbmc.org/showthread.php?tid=172801
# files
LOGFILE=/home/xbmc/idleshutdown_cron.log
LASTSTATEFILE=/home/xbmc/idleshutdown_laststate.txt
date >> $LOGFILE
# check if shutdown is allowed $? will be the result of checkshutdown.sh
/usr/bin/checkshutdown.sh >> $LOGFILE
SHUTDOWNFORBIDDEN="$?"
# get the last state of XBMC.InhibitIdleShutdown
LASTSTATE=`cat $LASTSTATEFILE`
if [ "$SHUTDOWNFORBIDDEN" -eq "0" ]; then
    # 0 means shutdown allowed -> do not inhibit shutdown from xbmc any more -> allow shutdown
    if [ "$LASTSTATE" -ne "0" ]; then
        # this resets the idle timer and should not be called unless change of the state has happened
        xbmc-send --action="XBMC.InhibitIdleShutdown(false)" >> $LOGFILE
        echo "0" > $LASTSTATEFILE
    else
        echo "Last state of XBMC.InhibitIdleShutdown was already 0. Do nothing to not disturb the idle timer" >> $LOGFILE
    fi
else
    # this inhibts idle shutdown and resets the idle timer
    xbmc-send --action="XBMC.InhibitIdleShutdown(true)" >> $LOGFILE
    echo "1" > $LASTSTATEFILE
fi


for interested readers who have gone this farBlush
/usr/bin/checkshutdown.sh
Code:
#!/bin/bash
# check if shutdown of the machine possible (xmbc and mythtv backend idle)
# returns 1 if shutdown allowed, otherwise 0
# sources:
# http://forum.xbmc.org/showthread.php?tid=127282

mythshutdown --check > /dev/null
if [ "$?" -ne "0" ]; then
    mythshutdown --status > /dev/null
    echo "Cannot suspend as mythbackend is not idle: status = '`echo $?`'"

    echo         0 - Idle
    echo         1 - Transcoding
    echo         2 - Commercial Flagging
    echo         4 - Grabbing EPG data
    echo         8 - Recording - only valid if flag is 1
    echo        16 - Locked
    echo        32 - Jobs running or pending
    echo        48 - Possibly 16 + 32
    echo        64 - In a daily wakeup/shutdown period
    echo       128 - Less than 30 minutes to next wakeup period
    echo       255 - Setup is running

    # TODO: List out the appropriate error message.
    #-s/--status         (returns a code indicating the current status)
    #         0 - Idle
    #         1 - Transcoding
    #         2 - Commercial Flagging
    #         4 - Grabbing EPG data
    #         8 - Recording - only valid if flag is 1
    #        16 - Locked
    #        32 - Jobs running or pending
    #        48 - Possibly 16 + 32
    #        64 - In a daily wakeup/shutdown period
    #       128 - Less than 30 minutes to next wakeup period
    #       255 - Setup is running
            exit 1
fi

if [ "`pidof -s xterm`" ]; then
        echo "Cannot suspend as a xterminal is open"
        exit 1
fi

if [ "`pidof -s synaptic`" ]; then
        echo "Cannot suspend as Synaptic package manager is running"
        exit 1
fi


if [ "`net status shares | wc -l`" -gt 3 ]; then
    # count lines of (sudo) net status shares. 3 Lines header
    echo "Cannot suspend as a samba share(s) is/are being used"
    net status shares
    exit 1
fi

if [ "`netstat | grep nfs`" ]; then
        echo "Cannot suspend as an NFS share is being used"
        exit 1
fi

NUSERS_TOTAL=`w -h | wc -l`
if [ "$NUSERS_TOTAL" -gt "1" ]; then
    echo "Cannot suspend the machine. $NUSERS_TOTAL users are logged in"
    exit 1
fi

if [ "`users`" != "xbmc" ]; then
        echo "Cannot suspend the machine as there are users other than xbmc: '`                               users`'"
        exit 1
fi



if [ "`pidof -s firefox-bin`" ]; then
        echo "Cannot suspend as Firefox is running"
        exit 1
fi


# shutdown allowed
echo "Allow shutdown"
exit 0
Reply
#7
How to get this working in Libreelec?

I don't use Mythtv, I will use it only for 3 RPi with LE7, one as a server and two clients. If one or both client are connected, the server should not shutdown. Otherwise after 5 or more minutes. Running smb share and the LAMP addon on the server RPi. This is for my car, only for music and movies for the childrens, so the server with external HDD should not run all the time to save battery power. Any help would be great. Thank you.
Reply
#8
Run this in your autostart.sh in the .config folder like this:
nohup script_name.sh &

#/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
Reply

Logout Mark Read Team Forum Stats Members Help
xbmc-send resets idle timer -> no shutdown0