Kodi Community Forum

Full Version: Shutdown computer via XBMC
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
One thing I like about XBMC (Xbox Version) is the ability to completely shutdown the system with just one press of a button. It's especially convenient when laying in bed at night and not be forced to get up and press buttons.

I don't know what would be the best way to implement it. First I was thinking about binding a button on the remote via Lirc and irexec to execute the shutdown -h now command but I would be a bummer if you accidentally pressed the button.

Another way would be to add a Shutdown Computer button next to the regular shutdown/System Info/Restart buttons in XBMC and have it execute a shutdown -h now command (or similar). Then add the necessary permissions to the user in order to use the shutdown command.

Any thoughts about this or a better way to implement this?
Hi,

I would do it in a different way.

There are already shutdown/restart buttons in the pop-up menu. Why not define 2 return codes, that will be send, when XBMC exits. So you could write a script that starts XBMC and reacts to the return code when XBMC has been exited.

I'm not really the dev kind of guy but it shouldn't be too hard to implement.
It's much easier to implement that inside xbmc. It's nothing more than define 3 or 4 system calls inside a .xml file (flags and command arguments may vary from distribution to distribution). A single routine inside xbmc would make the appropriate system call, depending on the choice.

We could have something like syscalls.xml

Code:
<syscalls>
    <shutdown>sudo /sbin/poweroff</shutdown>
    <hibernate>sudo /usr/sbin/hibernate</hibernate>
    <suspend>sudo /usr/sbin/suspend</suspend>
    <reload>kill -HUP `pidof XboxMediaCenter`</reload>
</syscalls>

My 2ยข,

Hugo Monteiro.
Has anyone implemented something like this?
I have implemented something like this externally.
I'm using the following script to probe the xbmc.log after it exists, i'm then looking for the specific button that was pressed, and the running a command.

It's pretty simple...

Code:
#!/bin/bash
XBMC_EXIT=""
./XboxMediaCenter -fs -q
XBMC_EXIT=$(/bin/grep -c 'To XBMC.ShutDown()' ./xbmc.log)
if [ $XBMC_EXIT -eq 1 ]; then
   echo $XBMC_EXIT
   echo "Shutting Down..."
shutdown -h now
else
   echo "Restarting..."
./XboxMediaCenter -fs -q
fi
Duduke,
Thanks, that works a treat after modding for my environment.
You're right it is easy, I guess I was just being lazy.
Cheer,
Hitman
Duduke this works really good but the problem I had was it works once only If you get to the restarting bit and it actually restarts it won't shutdown again. I kind of go around this by on restart recalling the script instead of xbmc might be wrong or bad I have no idea really

and also you have to be a root user to shutdown
Jezz-X
change permissions on /sbin/shutdown

Duduke
thx for the script, simple stuff always work great Smile
Rather than change perm on /sbin/shutdown I just update /etc/sudoers to allow my user to execute it without a password and my version of the script then issues "sudo /sbin/shutdown -h".

Jezz_X, good point, didn't even spot that.
This will loop forever (as long as it's restarted) and will quit on shutdown.

Code:
#!/bin/bash
XBMC_EXIT=""
./XboxMediaCenter -fs -q
while [ "$XBMC_EXIT" != "1" ];
do
    XBMC_EXIT=$(/bin/grep -c 'To XBMC.ShutDown()' ./xbmc.log)
    if [ $XBMC_EXIT -eq 1 ]; then
       echo $XBMC_EXIT
       echo "Shutting Down..."
#    shutdown -h now
    else
       echo "Restarting..."
    ./XboxMediaCenter -fs -q
    fi
done
sorry, i've commented out the shutdown...

Code:
#!/bin/bash
XBMC_EXIT=""
./XboxMediaCenter -fs -q
while [ "$XBMC_EXIT" != "1" ];
do
    XBMC_EXIT=$(/bin/grep -c 'To XBMC.ShutDown()' ./xbmc.log)
    if [ $XBMC_EXIT -eq 1 ]; then
       echo $XBMC_EXIT
       echo "Shutting Down..."
    shutdown -h now
    else
       echo "Restarting..."
    ./XboxMediaCenter -fs -q
    fi
done
neverind ....
I added a feature that you can call System.Exec("/bin/whatever command") from the skin.
Any hint on how do I go about implementing that?
Pages: 1 2 3 4