SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-02-09 08:32:03

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

openbox-logout + suspend / hibernate

if you encounter problems please tell me here
so far 1 person has a problem with the old script

update: Feb 13

------------------------------------------------

3Igv.png

click here to see the new one

------------------------------------------------







it always bothered me that the openbox-logout-script-basic script never had a suspend button (and who uses that?) and the openbox-logout-script acted kind of strange when pressing the suspend and hibernate buttons so i decided to check the script out myself

now it has a nothing-strange-working suspend button

3drq.jpg

just

gksu gedit /usr/bin/openbox-logout

and replace that code with this
(you can back up your old code first but it's not really necessary since the openbox-logout-script and openbox-logout-script-basic are both in the repos)

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    # Suspend
    def suspend(self, widget):
        os.system("dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Suspend")

    # Logout
    def logout(self, widget):
        os.system("openbox --exit")

    # Reboot
    def reboot(self, widget):
        os.system("gdm-control --reboot && openbox --exit")

    # Shutdown
    def shutdown(self, widget):
        os.system("gdm-control --shutdown && openbox --exit")

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Exit? Choose an option:")
        self.window.set_resizable(False)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)

        # Create a box to pack widgets into
        self.box1 = gtk.HBox(False, 0)
        self.window.add(self.box1)

        # Create cancel button
        self.button1 = gtk.Button("_Cancel")
        self.button1.set_border_width(10)
        self.button1.connect("clicked", self.delete_event, "Changed me mind :)")
        self.box1.pack_start(self.button1, True, True, 0)
        self.button1.show()
        
        # Create suspend button
        self.button2 = gtk.Button("S_uspend")
        self.button2.set_border_width(10)
        self.button2.connect("clicked", self.suspend)
        self.button2.connect("clicked", self.delete_event, "Force removal :(")
        self.box1.pack_start(self.button2, True, True, 0)
        self.button2.show()

        # Create logout button
        self.button3 = gtk.Button("_Log out")
        self.button3.set_border_width(10)
        self.button3.connect("clicked", self.logout)
        self.box1.pack_start(self.button3, True, True, 0)
        self.button3.show()

        # Create reboot button
        self.button4 = gtk.Button("_Reboot")
        self.button4.set_border_width(10)
        self.button4.connect("clicked", self.reboot)
        self.box1.pack_start(self.button4, True, True, 0)
        self.button4.show()

        # Create shutdown button
        self.button5 = gtk.Button("_Shutdown")
        self.button5.set_border_width(10)
        self.button5.connect("clicked", self.shutdown)
        self.box1.pack_start(self.button5, True, True, 0)
        self.button5.show()
        
        self.box1.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    gogogo = DoTheLogOut()
    main()

Last edited by ali (2011-02-13 20:17:47)

Offline

Help fund CrunchBang, donate to the project!

#2 2011-02-09 10:08:26

corenominal
root
From: Lincoln, UK
Registered: 2008-11-20
Posts: 4,887
Website

Re: openbox-logout + suspend / hibernate

Nice, I will try and check this out. Also, I think these scripts will need updating soon as I am not sure if 'gdm-control' will be supported in the future. hmm

Offline

#3 2011-02-09 10:18:19

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

well, you could use dbus to shutdown and reboot as well, it'll work but not as smooth and clean as gdm-control

Last edited by ali (2011-02-09 10:18:50)

Offline

#4 2011-02-09 17:14:52

axcraig
#! Member
Registered: 2011-02-05
Posts: 95

Re: openbox-logout + suspend / hibernate

Great post thanks.

I needed this today but didn't know how to do it. Now I do.

Cheers,
AX

Offline

#5 2011-02-09 17:35:49

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

i'm glad this helps you smile

Offline

#6 2011-02-10 03:11:52

midnightrider
Member
Registered: 2011-01-21
Posts: 32

Re: openbox-logout + suspend / hibernate

@ali, I am having trouble with shutdown when using both the openbox-logout-script-basic script and the openbox-logout-script. You mention using dbus as a replacement. Can you explain exactly how this is done? Thanks!


"Don't you draw the queen of diamonds, boy, she'll beat you if she's able. You know the queen of hearts is always your best bet."

                                                                                                                    - Glenn Frey & Don Henley

Offline

#7 2011-02-10 06:11:48

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

replace the text from inside the single quotes on line 29 (make sure not to ruin the indentation since python is very strict on that
replace
os.system("gdm-control --shutdown && openbox --exit")
to

os.system("dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown")

but that won't display the services shutting down UNLESS you're in a tty

maybe corenominal or someone who has some experience with linux can help us figure out how to get to a tty that would be so cool
(what command is executed when pressing C-A-F1!?)
once you figure that out it's really easy

Last edited by ali (2011-02-10 06:27:50)

Offline

#8 2011-02-10 20:35:49

midnightrider
Member
Registered: 2011-01-21
Posts: 32

Re: openbox-logout + suspend / hibernate

@ali, I made the changes by following your excellent instructions and I am happy to report the problem is solved, success achieved! Your help is greatly appreciated. smile


"Don't you draw the queen of diamonds, boy, she'll beat you if she's able. You know the queen of hearts is always your best bet."

                                                                                                                    - Glenn Frey & Don Henley

Offline

#9 2011-02-10 20:39:04

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

glad your problem was solved smile

Last edited by ali (2011-02-10 20:44:41)

Offline

#10 2011-02-12 15:22:34

marcdutonkin
New Member
Registered: 2011-02-12
Posts: 1

Re: openbox-logout + suspend / hibernate

Hello Ali,

On my system, your code for suspend sems to do nothing :

os.system("dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Suspend")

This one is running well :
       os.system("dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0"). smile

Offline

#11 2011-02-13 04:37:19

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

good to know


#! ~/ $ lshal | grep power_management.can
  power_management.can_hibernate = true  (bool)
  power_management.can_suspend = true  (bool)
  power_management.can_suspend_hybrid = true  (bool)

looks like hal works on my machine too, maybe i'll start using that instead

Last edited by ali (2011-02-13 06:13:13)

Offline

#12 2011-02-13 04:40:18

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

new openbox-logout:

3Igv.png

what has changed?
- added hibernate button
- dbus signals handled by hal now smile
- changed key shortcuts to alt + 1...6 (makes my life easier, the syntax is simple if you want to change it back tongue)

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    # Suspend
    def suspend(self, widget):
        os.system("kill `ps -ef | grep /usr/bin/openbox-logout | grep -v grep | awk '{print $2}'` && dbus-send --system --print-reply --dest=\"org.freedesktop.Hal\" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0")

    # hibernate
    def hibernate(self, widget):
        gtk.main_quit()
        os.system("kill `ps -ef | grep /usr/bin/openbox-logout | grep -v grep | awk '{print $2}'` && dbus-send --system --print-reply --dest=\"org.freedesktop.Hal\" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate")

    # Logout
    def logout(self, widget):
        os.system("openbox --exit")

    # Reboot
    def reboot(self, widget):
        os.system("gdm-control --reboot && openbox --exit")

    # Shutdown
    def shutdown(self, widget):
        os.system("gdm-control --shutdown && openbox --exit")

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("Exit? Choose an option:")
        self.window.set_resizable(False)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)

        # Create a box to pack widgets into
        self.box1 = gtk.HBox(False, 0)
        self.window.add(self.box1)

        # Create cancel button
        self.button1 = gtk.Button("_1. Cancel")
        self.button1.set_border_width(10)
        self.button1.connect("clicked", self.delete_event, "Changed me mind :)")
        self.box1.pack_start(self.button1, True, True, 0)
        self.button1.show()
        
        # Create suspend button
        self.button2 = gtk.Button("_2. Suspend")
        self.button2.set_border_width(10)
        self.button2.connect("clicked", self.suspend)
        self.box1.pack_start(self.button2, True, True, 0)
        self.button2.show()

        # Create hibernate button
        self.button3 = gtk.Button("_3. Hibernate")
        self.button3.set_border_width(10)
        self.button3.connect("clicked", self.hibernate)
        self.box1.pack_start(self.button3, True, True, 0)
        self.button3.show()

        # Create logout button
        self.button4 = gtk.Button("_4. Log out")
        self.button4.set_border_width(10)
        self.button4.connect("clicked", self.logout)
        self.box1.pack_start(self.button4, True, True, 0)
        self.button4.show()

        # Create reboot button
        self.button5 = gtk.Button("_5. Reboot")
        self.button5.set_border_width(10)
        self.button5.connect("clicked", self.reboot)
        self.box1.pack_start(self.button5, True, True, 0)
        self.button5.show()

        # Create shutdown button
        self.button6 = gtk.Button("_6. Shutdown")
        self.button6.set_border_width(10)
        self.button6.connect("clicked", self.shutdown)
        self.box1.pack_start(self.button6, True, True, 0)
        self.button6.show()
        
        self.box1.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    gogogo = DoTheLogOut()
    main()

you may notice i killed the process prematurely, since it kills only the process /usr/bin/openbox-logout, it's safe (it only runs if /usr/bin/openbox-logout is running, if you run the script from another location it wont run)


------------------------------------



if you don't mind the delay change or simply want to keep it clean
change

os.system("kill `ps -ef | grep /usr/bin/openbox-logout | grep -v grep | awk '{print $2}'` && dbus-send --system --print-reply --dest=\"org.freedesktop.Hal\" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0")

        os.system("kill `ps -ef | grep /usr/bin/openbox-logout | grep -v grep | awk '{print $2}'` && dbus-send --system --print-reply --dest=\"org.freedesktop.Hal\" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate")

to

os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.Hal\" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Suspend int32:0")

        os.system("dbus-send --system --print-reply --dest=\"org.freedesktop.Hal\" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate")

and add anywhere in __init__ after button 2 && 3 were initialized

        self.button3.connect("clicked", self.delete_event, "")
        self.button2.connect("clicked", self.delete_event, "")

Last edited by ali (2011-02-13 10:55:56)

Offline

#13 2011-02-14 09:08:22

Sveep
New Member
Registered: 2011-02-07
Posts: 2

Re: openbox-logout + suspend / hibernate

When I shutdown or reboot, I get a high resolution "shutdown" or "reboot". I like it and would like something  like "CrunchBang  linux loading" as a bootsplash. And no progressbar or "loading, please wait"

Offline

#14 2011-02-14 14:38:23

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

i dont really understand what you're asking me

Offline

#15 2011-02-14 15:07:08

anonymous
The Mystery Member
From: Arch Linux Forums
Registered: 2008-11-29
Posts: 8,904

Re: openbox-logout + suspend / hibernate

@Sveep - if you want to a make a feature request, please post here instead:

http://crunchbanglinux.org/forums/forum … ggestions/


Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Offline

#16 2011-02-14 23:28:45

Criminal
#! Member
Registered: 2010-02-26
Posts: 62

Re: openbox-logout + suspend / hibernate

Hi!
Nice script. but hibernate doesn't work for me. The only thing I notice is, that my network connection gets killed and established again.

When starting the script from terminal with sudo I am getting following response:

~$ method return sender=:1.0 -> dest=:1.95 reply_serial=2
   int32 128

Without sudo I don't have permission to kill stuff.

Would be glad if you could help me with that, because I really like hibernation.

Offline

#17 2011-02-15 03:40:51

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

make sure you have enough swap space and that it's mounted (as i think that when you hibernate your ram memory is transfered to swap)
hibernate always fails as far as i know if swap is not mounted

execute this script
see if any of them work and come back to tell me
needless to say, make sure you save all your files in case the pc shuts down instead of hibernates

(after executing a command, you can't execute another until you close the terminal that automatically opens if it works)

#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
import os

class DoTheLogOut:

    # Cancel/exit
    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

    # Hal
    def hal(self, widget):
        os.system("terminator --command=\"dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate && sleep \"")

    # DeviceKit
    def dk(self, widget):
        os.system("terminator --command=\"dbus-send --print-reply --system --dest=org.freedesktop.DeviceKit.Power /org/freedesktop/DeviceKit/Power org.freedesktop.DeviceKit.Power.Hibernate && sleep \"")

    # UPower
    def upower(self, widget):
        os.system("terminator --command=\"dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Hibernate && sleep 20s\"")

    # PowerManagement
    def pm(self, widget):
        os.system("terminator --command=\"dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Hibernate && sleep 20s\"")
        
   # gnome.PowerManager
    def gpm(self, widget):
        os.system("terminator --command=\"dbus-send --session --dest=org.gnome.PowerManager --type=method_call --print-reply --reply-timeout=2000 /org/gnome/PowerManager org.gnome.PowerManager.Hibernate && sleep 20s\"")

    def __init__(self):
        # Create a new window
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_title("which one?")
        self.window.set_resizable(False)
        self.window.set_position(1)
        self.window.connect("delete_event", self.delete_event)
        self.window.set_border_width(20)

        # Create a box to pack widgets into
        self.box1 = gtk.HBox(False, 0)
        self.window.add(self.box1)
        
        # Create hal button
        self.button2 = gtk.Button("Hal")
        self.button2.set_border_width(10)
        self.button2.connect("clicked", self.hal)
        self.box1.pack_start(self.button2, True, True, 0)
        self.button2.show()

        # Create devicekit button
        self.button3 = gtk.Button("DeviceKit")
        self.button3.set_border_width(10)
        self.button3.connect("clicked", self.dk)
        self.box1.pack_start(self.button3, True, True, 0)
        self.button3.show()

        # Create upower button
        self.button4 = gtk.Button("Upower")
        self.button4.set_border_width(10)
        self.button4.connect("clicked", self.upower)
        self.box1.pack_start(self.button4, True, True, 0)
        self.button4.show()

        # Create PowerManagement button
        self.button5 = gtk.Button("PowerManagement")
        self.button5.set_border_width(10)
        self.button5.connect("clicked", self.pm)
        self.box1.pack_start(self.button5, True, True, 0)
        self.button5.show()

        # Create g.PowerManagement button
        self.button6 = gtk.Button("g.PowerManagement")
        self.button6.set_border_width(10)
        self.button6.connect("clicked", self.gpm)
        self.box1.pack_start(self.button6, True, True, 0)
        self.button6.show()
        
        self.box1.show()
        self.window.show()

def main():
    gtk.main()

if __name__ == "__main__":
    gogogo = DoTheLogOut()
    main()

my outcome was:
Hal - works
DeviceKit - nothing happens
UPower - works
PowerManagement - works
gnome.PowerManagement - nothing happens

Last edited by ali (2011-02-15 07:16:31)

Offline

#18 2011-02-15 09:13:38

Criminal
#! Member
Registered: 2010-02-26
Posts: 62

Re: openbox-logout + suspend / hibernate

Thanks for the quick reply.

My swap partition is 1.5 times the size of my ram (Ram: 2 GB, Swap: 2.93 according to gparted) and mounted (checked with fdisk -l). I'm not sure if that's enough for hal etc., but since my ram never holds more than 700 MB of data it should be. When trying you script there were only 230 MB in ram. Swap is hardly ever used.

my outcome:
Hal - network connection restarts and that's it
DeviceKit - nothing
UPower - nothing
PowerManagement - locks screen, restarts network connection and wants my password to keep working. no hibernation though
gnome.PowerManagement - nothing (not installed I think)

I modified your script a little (removed the extra instance of terminator) to get the responses in command line:
DeviceKit, UPower and gnomePowerManagement were not provided by any service. So they seem not to be installed or running.

Will try installing gnome Powermanagement and see what that does.

Edit:
Just did that:

Error org.freedesktop.DBus.Error.UnknownMethod: Method "Hibernate" with signature "" on interface "org.gnome.PowerManager" doesn't exist

when running without new terminator window. Else nothing happens.

Last edited by Criminal (2011-02-15 09:21:44)

Offline

#19 2011-02-15 09:30:10

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

that's really strange...
what about

gksu pm-hibernate

Offline

#20 2011-02-15 09:41:11

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

also i noticed there's a  hibernate package in the repositories
try installing and running it if everything else fails

~/ $ sudo aptitude search hibernate
p   hibernate                                                           - smartly puts your computer to sleep (suspend to RAM or disk)                 
[...]
~/ $ 

Offline

#21 2011-02-15 09:41:26

Criminal
#! Member
Registered: 2010-02-26
Posts: 62

Re: openbox-logout + suspend / hibernate

The same like hal: network gets shut down and reconnects.

I tried a way larger swap partition for testing as well. No change.
Could there be a hardware issue?

By the way: output of

lshal | grep power_management.can

is true for all three instances

Offline

#22 2011-02-15 09:43:33

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

i hope not, try the hibernate package

sudo aptitude install hibernate

then

hibernate

and if that doesn't work try

hibernate --force

Last edited by ali (2011-02-15 09:49:19)

Offline

#23 2011-02-15 11:21:07

Criminal
#! Member
Registered: 2010-02-26
Posts: 62

Re: openbox-logout + suspend / hibernate

tried that and it seems to be a push in the right direction.
When running either hibernate or hibernate --force I get following error:

hibernate:Warning: Tuxonice binary signature file not found.
You haven't specified a resume=/resume2= parameter on your kernel command line

Your GRUB or LILO config should have something like resume=swap:/dev/hdaX
where /dev/hdaX is your swap partition. You will then need to either reboot
after doing so or set it manually (this time only) using:
    echo swap:/dev/hdaX > /sys/power/tuxonice/resume
hibernate: Aborting.
ERROR: Module tuxonice_core is in use by tuxonice_bio

I added the line

resume=swap:/dev/sda1

at the end of my grub.cfg and rebooted, but no change. Seems like I'm missing a step. Do you have an idea?

I'll be away for some hours now. Will report back later.
Thanks for your help! I really appreciate that.

Offline

#24 2011-02-15 11:28:54

ali
#! Die Hard
Registered: 2010-05-31
Posts: 1,034

Re: openbox-logout + suspend / hibernate

no idea, you swap is on /dev/sda1?

Offline

Help fund CrunchBang, donate to the project!

#25 2011-02-15 17:59:23

Criminal
#! Member
Registered: 2010-02-26
Posts: 62

Re: openbox-logout + suspend / hibernate

swap is on /dev/sda1.
I had to put the entry to the end of the linux line in grub.cfg.

Laptop goes down for hibernation and hibernation.log looks good as well. But it doesn't wake up again. Booting stops at the time when normaly the gdm screen would appear or - when hibernating - my desktop should show. It freezes for a short time and then reboots without hibernating.

kern.log says that tuxonice is not running yet, but I can't remember having installed that one. Isn't that a kernel patch?

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo