You are not logged in.

#1 2008-11-03 20:46:26

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Howto: suspend from the command line!

I just discovered how to do this... Put this in a script:

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

And execute that script, and presto, your system will suspend - absolutely no lxsession or anything needed, only HAL and pm-utils. Woo hoo!

Offline

#2 2008-11-03 20:53:04

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Re: Howto: suspend from the command line!

Update: And use this for hibernate:

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

Offline

#3 2008-11-03 20:54:38

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Howto: suspend from the command line!

Why not just run pm-suspend or pm-hibernate respectively?


thayer williams ~ cinderwick.ca

Offline

#4 2008-11-03 21:13:41

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Re: Howto: suspend from the command line!

Because those have to be run as root... Using sudo is inconvenient for use with e.g. window manager menus, and using it with NOPASSWD strikes me as hackish...

So I guess that means I went to the trouble of looking this up for aesthetic reasons. Perhaps I should see a shrink. wink

Offline

#5 2008-11-07 04:59:36

BKJ
Member
Registered: 2008-09-19
Posts: 71

Re: Howto: suspend from the command line!

Nice...  I was using good ole' sudo with NOPASSWD for suspend/hibernate.  Only addition that I made was to add this command as the first line:

xscreensaver-command -lock

I wanted my screen to be locked after recovering from hibernate/suspend.

Thanks for the info.

Offline

#6 2008-11-07 05:35:03

pelle.k
Member
From: Åre, Sweden (EU)
Registered: 2006-04-30
Posts: 667

Re: Howto: suspend from the command line!

Because those have to be run as root...

hmm. that quite clever. why didn't i think of that! I always ran pm-* using NOPASSWD too.
Thanks for sharing smile


"Your beliefs can be like fences that surround you.
You must first see them or you will not even realize that you are not free, simply because you will not see beyond the fences.
They will represent the boundaries of your experience."

SETH / Jane Roberts

Offline

#7 2008-11-07 06:36:29

mentallaxative
Member
From: Australia
Registered: 2008-07-14
Posts: 134
Website

Re: Howto: suspend from the command line!

GJ, I'm not sure how you see using NOPASSWD as hackish, but writing out a long dbus command is not.

Still, nice to know.

Offline

#8 2008-11-28 08:56:37

pelle.k
Member
From: Åre, Sweden (EU)
Registered: 2006-04-30
Posts: 667

Re: Howto: suspend from the command line!

I'm testing fedora out ATM, and there is this nifty command you may run as an ordinary user, IF you've got gnome-power-manager installed.

gnome-power-cmd.sh <suspend/hibernate/restart/shutdown>

It does it "properly" under gnome, i.e. activating screensaver and resuming removable devices correctly on resume, unlike the "raw" method posted above.
It's supposedly not fedora specific, but included with gnome-power-manager, so try it out.

What it does is something similar (just replace suspend with desired action);

        dbus-send --session --dest=org.freedesktop.PowerManagement              \
                  --type=method_call --print-reply --reply-timeout=2000 \
                  /org/freedesktop/PowerManagement                      \
                  org.freedesktop.PowerManagement.suspend

"Your beliefs can be like fences that surround you.
You must first see them or you will not even realize that you are not free, simply because you will not see beyond the fences.
They will represent the boundaries of your experience."

SETH / Jane Roberts

Offline

#9 2008-11-28 14:42:04

raf_kig
Member
Registered: 2008-11-28
Posts: 143

Re: Howto: suspend from the command line!

Aehm you dont need hal/pm-utils for suspending.
May i suggest

 echo mem > /sys/power/state

?

:-)

Regards

raf

Last edited by raf_kig (2008-11-28 14:43:10)

Offline

#10 2008-11-28 15:17:59

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: Howto: suspend from the command line!

raf_kig wrote:

Aehm you dont need hal/pm-utils for suspending.
May i suggest

 echo mem > /sys/power/state

?

:-)

Regards

raf

This looks cool.. /me googles

but!
- you need a shell to do the redirection
- you still need root priveleges because only root can write there


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#11 2008-11-28 15:23:38

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Howto: suspend from the command line!

raf_kig wrote:

Aehm you dont need hal/pm-utils for suspending.
May i suggest

 echo mem > /sys/power/state

While that's true, it doesn't accomodate quirks, which is the primary advantage of pm-utils.  Then again, Gullible's script requires the HAL and DBUS daemons, and pm-utils requires DBUS, while the 'mem' requires neither.  So it really just comes down to what you already have running on your system.


thayer williams ~ cinderwick.ca

Offline

#12 2008-11-28 16:48:16

raf_kig
Member
Registered: 2008-11-28
Posts: 143

Re: Howto: suspend from the command line!

Dieter@be wrote:

- you need a shell to do the redirection
- you still need root priveleges because only root can write there

an appropriate sudoers entry solves that problem :-)

thayer wrote:

While that's true, it doesn't accomodate quirks, which is the primary advantage of pm-utils.

From my experience this is mostly not needed anymore. Nowadays all my machines 'just work' (used to be different a few years ago).

Regards

raf

Offline

#13 2008-11-28 22:52:55

louiswins
Member
Registered: 2007-12-02
Posts: 6

Re: Howto: suspend from the command line!

Gullible Jones wrote:
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
 /org/freedesktop/Hal/devices/computer \
 org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \
 int32:0

And execute that script, and presto, your system will suspend - absolutely no lxsession or anything needed, only HAL and pm-utils. Woo hoo!

For some reason, this works for me, but "gnome-power-cmd.sh suspend" does not. The dbus one puts my computer to sleep alright, but when I try to use gnome-power-cmd.sh or press the suspend button on my laptop, it beeps at me and does nothing. Neither the shutdown menu nor the power preferences menu give me the option of suspend (or hibernate, but I don't use that). This is really confusing me, because it worked fine under Ubuntu, and it works with pm-suspend and with pure HAL (the dbus command above), but not with GNOME for some reason.

The output of "gnome-power-cmd.sh suspend" is:

Suspending
Error org.freedesktop.DBus.GLib.UnmappedError.GpmControlError.Code0: Cannot suspend as not allowed from policy
Failed

Does anyone have any ideas for me? I'm in the hal and power groups, so I don't know why it's "not allowed from policy".

Offline

#14 2008-12-01 18:24:21

sredna
Member
Registered: 2008-11-29
Posts: 50

Re: Howto: suspend from the command line!

I have the problem that I can not suspend/hibernate my system at all, except for using the 'echo mem > /sys/power/state' trick found in this thread.

Trying the dbus command has this result:

anders@mars ~ $ dbus-send --system --print-reply --dest=org.freedesktop.Hal \
>  /org/freedesktop/Hal/devices/computer \
>  org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \
>  int32:0
method return sender=:1.0 -> dest=:1.309 reply_serial=2
   int32 1

Do you know why, or how I can fix that? Any help would be greatly appreciated!

Offline

#15 2009-04-14 03:16:05

quantumphaze
Member
From: Melbourne, Australia
Registered: 2008-11-14
Posts: 175

Re: Howto: suspend from the command line!

Sorry to bring this thread back from the dead but I seem to be having some permission problems with dbus:

Error org.freedesktop.Hal.Device.PermissionDeniedByPolicy: org.freedesktop.hal.power-management.suspend no <-- (action, result)

This happened to my Acer laptop a while ago since the suspend option in KDE suddenly stopped working. I simply thought it was a dodgy config. But then I tried it on my new laptop (ThinkPad SL500) and got the same with a fresh install with default configs.

At least acpid picks up Fn+F4

EDIT: I should also add that it works if I run it as root

Last edited by quantumphaze (2009-04-14 12:04:41)


▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁

Offline

#16 2009-04-17 11:10:28

dobedo
Member
From: Belgium
Registered: 2008-10-04
Posts: 113

Re: Howto: suspend from the command line!

Wiki: http://wiki.archlinux.org/index.php/HAL
I would say you have to edit /etc/PolicyKit/PolicyKit.conf like this:

        <match user="$USER">
            <match action="org.freedesktop.hal.power-management.suspend">
                <return result="yes"/>
            </match>
        </match>

=> change the $USER to yours and restart hal, dbus and KDE.

...better to create a new post than resurect an old one ;-)

Offline

#17 2009-04-17 11:57:26

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Howto: suspend from the command line!

I disagree. When it's relevent, it's better to keep the old thread rather than duplicating.

Offline

#18 2009-04-17 13:46:43

quantumphaze
Member
From: Melbourne, Australia
Registered: 2008-11-14
Posts: 175

Re: Howto: suspend from the command line!

Thanks, worked perfectly on my old laptop. Suspend from KDE now works fine on the new laptop, PolicyKit/HAL/DBus fixed itself somehow.

Last edited by quantumphaze (2009-04-17 13:47:33)


▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁

Offline

#19 2009-05-11 16:01:11

psybeer
Member
Registered: 2009-01-16
Posts: 14

Re: Howto: suspend from the command line!

To continue on a related issue... what if pm-suspend does nothing? It doesn't even an error to the /var/logs

How can I see where the problem is?

Offline

#20 2009-05-12 09:07:52

quantumphaze
Member
From: Melbourne, Australia
Registered: 2008-11-14
Posts: 175

Re: Howto: suspend from the command line!

psybeer wrote:

What if pm-suspend does nothing?

Try this

echo mem > /sys/power/state

This talks to the system on a lower level than acpid or pm-utils. If that does nothing (remember that a locked up system is still something) then there are bigger problems.

Make sure that the packages acpi and acpid are installed and that you run pm-suspend from a root terminal, or better still as root in a tty.


▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁

Offline

#21 2011-09-19 20:19:25

wombalton
Member
Registered: 2011-07-18
Posts: 17

Re: Howto: suspend from the command line!

Hi there,

I have to bring this up again. What is the damn comand for suspend/hibernating from userspace? I works fine if I use the lxde-logout programm, but what does that do??
the mentioned dbus entrys dont work for me:

$ dbus-send --session --dest=org.freedesktop.PowerManagement --type=method_call --print-reply --reply-timeout=2000 /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.suspend

Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.PowerManagement was not provided by any .service files

I have pm-utils installed and have a hook for locking my screen on suspend. This works well if I use the pm-suspend comand, but not with the lxde-logout programm. So I tried to find out what lxde-logout is doing to change it in that way that the hook is executed but I can't find the right stuff in the web.

Has Anyone any ideas? Please help.

Last edited by wombalton (2011-09-19 20:19:50)

Offline

#22 2011-09-19 20:30:03

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: Howto: suspend from the command line!

wombalton,
this thread is over two years old. Please do not necropost: https://wiki.archlinux.org/index.php/Fo … Bumping.27
Best open a new thread of your own and link back here.

Closing this one.


To know or not to know ...
... the questions remain forever.

Offline

Board footer

Powered by FluxBB