Page 1 of 2

shutdown, hibernate and suspend a linux system

Posted: September 25th, 2009, 11:28 am
by carresmd
I have written some code that enables the shutdown, hibernate and suspend functions for linux when the download queue has finished. I would like to see this included in 0.5 as we are basing LottaNZB 0.6 on SABnzbd 0.5 :D.

It basically uses DBus and HAL (to support older distributions) and ConsoleKit/DeviceKit-power (to support newer distributions), I think the code is pretty much self explanatory.

Thanks

Re: shutdown, hibernate and suspend a linux system

Posted: September 25th, 2009, 12:14 pm
by shypike
Thanks, quite interesting.
My Linux knowledge is quite superficial, hence the question:
This is portable over the different distributions and will not cause problems when not supported by the platform?

I think we can include it in release 0.5.0.

Re: shutdown, hibernate and suspend a linux system

Posted: September 25th, 2009, 12:40 pm
by carresmd
shypike wrote: Thanks, quite interesting.
My Linux knowledge is quite superficial, hence the question:
This is portable over the different distributions and will not cause problems when not supported by the platform?

I think we can include it in release 0.5.0.
It will work on probably 99% of the systems running a graphical environment. This code is targeted at desktop system because it would be kind of pointless to shutdown, hibernate or suspend a server via SABnzbd. If the platform doesn't support these things the code will handle it.

For example the shutdown code;
It will try to shutdown using HAL, if that isn't supported it will try ConsoleKit and if that isn't supported it will just shutdown SABnzbd itself.

Code: Select all

try:
    import dbus
except ImportError:
    pass
else:
    try:
        name = 'org.freedesktop.PowerManagement'
        path = '/org/freedesktop/PowerManagement'
        interface = 'org.freedesktop.PowerManagement'
        bus = dbus.SessionBus()
        proxy = bus.get_object(name, path)
    except dbus.exceptions.DBusException:
        try:
            name = 'org.freedesktop.ConsoleKit'
            path = '/org/freedesktop/ConsoleKit/Manager'
            interface = 'org.freedesktop.ConsoleKit.Manager'
            bus = dbus.SystemBus()
            proxy = bus.get_object(name, path)
        except dbus.exceptions.DBusException:
            pass
        else:
            if proxy.CanStop(dbus_interface=interface):
                proxy.Stop(dbus_interface=interface)
    else:
        if proxy.CanShutdown():
            proxy.Shutdown(dbus_interface=interface)
finally:
    os._exit(0)

Re: shutdown, hibernate and suspend a linux system

Posted: September 25th, 2009, 3:47 pm
by shypike
Thanks for your explanation.

Re: shutdown, hibernate and suspend a linux system

Posted: September 30th, 2009, 3:55 am
by carresmd
Hi shypike, any news regarding my patch? ::)

Re: shutdown, hibernate and suspend a linux system

Posted: September 30th, 2009, 5:53 am
by shypike
carresmd wrote: Hi shypike, any news regarding my patch? ::)
It will be included, but current the development pace of SABnzbd is quite low.

Re: shutdown, hibernate and suspend a linux system

Posted: September 30th, 2009, 8:53 am
by carresmd
shypike wrote: It will be included, but current the development pace of SABnzbd is quite low.
Great to hear that! Not so much about the development pace though, but that's just how stuff goes.

Re: shutdown, hibernate and suspend a linux system

Posted: October 2nd, 2009, 11:43 am
by shypike
It will take some rewriting, because your code isn't compatible with Python 2.4.
(Due to the try/except/else).

I'm skipping it for Alpha6.

Re: shutdown, hibernate and suspend a linux system

Posted: October 2nd, 2009, 12:45 pm
by carresmd
Oops, didn't think about backwards compatibility at all.
Well I'm just pretty new to this Python stuff (maybe 2 months now) so don't know the features in previous version and what not.
Anyway, if you think you're short on free-time or interest to rewrite this, I'm happy to rewrite it myself.
Let me know :)

Re: shutdown, hibernate and suspend a linux system

Posted: October 2nd, 2009, 1:40 pm
by carresmd
I have modified my patch to be backwards compatible with Python 2.4.
It's a very small edit though. 2 lines removed and 3 lines added.

Re: shutdown, hibernate and suspend a linux system

Posted: October 2nd, 2009, 1:53 pm
by shypike
Great, thank you. But it wasn't just the compatibility.
I just want some time to test a bit more and 0.5.0Alpha6 is going out this weekend.
It will be in 0.5.0 any way.

Re: shutdown, hibernate and suspend a linux system

Posted: October 16th, 2009, 4:26 pm
by shypike
It has been implemented for release 0.5.0 under Ticket #329.
Thanks for your assistence!

Re: shutdown, hibernate and suspend a linux system

Posted: October 16th, 2009, 5:00 pm
by carresmd
Thank you for implementing it! Looking forward to the 0.5(.0) release! :D

If it is not too much of a hassle, I'd like to be 'credited' with my full name, 'Marcel de Vries', and perhaps my email, 'marceldevries__AT__phannet.cc' (replace '__AT__' with '@'). As I only use my nickname to login and generally use my full name for everything else. Not required though, just a kind request. (I'm doing my best not to sound rude) ::)

Thanks again!

Re: shutdown, hibernate and suspend a linux system

Posted: October 17th, 2009, 3:34 am
by shypike
I'll add your credit line to the source code (end of misc.py).
It's not exactly like you wrote it,  I chose to reshuffle it quite a bit.
I can add you to the list of Release Testers, that will give you access to pre-built binaries.
(Although currently we have none with your code in it).

Re: shutdown, hibernate and suspend a linux system

Posted: October 17th, 2009, 4:26 am
by carresmd
Yeah, already saw the code changes you made. Looking good! ;)

You can add me to the Release Testers if you want to. I generally run the trunk code, but I'm happy to test release(s) (candidates)! Especially the 0.5(.0) release, as we depend on it. :D