23 07 | 2014

GNU/Linux graphic sessions: suspending your computer

Written by Tanguy

Classified in : Homepage, Debian, Command line, To remember

Major desktop environments such as Xfce or KDE have a built-in computer suspend feature, but when you use a lighter alternative, things are a bit more complicated, because basically: only root can suspend the computer. There used to be a standard solution to that, using a D-Bus call to a running daemon upowerd. With recent updates, that solution first stopped working for obscure reasons, but it could still be configured back to be usable. With newer updates, it stopped working again, but this time it seems it is gone for good:

$ dbus-send --system --print-reply \
            --dest='org.freedesktop.UPower' \
            /org/freedesktop/UPower org.freedesktop.UPower.Suspend
Error org.freedesktop.DBus.Error.UnknownMethod: Method "Suspend" with
signature "" on interface "org.freedesktop.UPower" doesn't exist

The reason seems to be that upowerd is not running, because it no longer provides an init script, only a systemd service. So, if you do not use systemd, you are left with one simple and stable solution: defining a sudo rule to start the suspend or hibernation process as root. In /etc/sudoers.d/power:

%powerdev ALL=NOPASSWD: /usr/sbin/pm-suspend, \
                        /usr/sbin/pm-suspend-hybrid, \
                        /usr/sbin/pm-hibernate

That allows members of the powderdev group to run sudo pm-suspend, sudo pm-suspend-hybrid and sudo pm-hibernate, which can be used with a key binding manager such as your window manager's or xbindkeys. Simple, efficient, and contrary to all that ever-changing GizmoKit and whatsitd stuff, it has worked and will keep working for years.

17 comments

wednesday 23 july 2014 à 16:21 michael said : #1

So everyone in the powerdev group can suspend the computer, even if someone else is currently using it?

wednesday 23 july 2014 à 16:30 Tanguy said : #2

@michael : Yes indeed, as in the old times, and it allows people to do no-so-funny jokes to other users. There used to be a more precise solution to that, with UPower and PolicyKit (or perhaps ConsoleKit, I never understood which one was what), but that solution appears to have gone away.

wednesday 23 july 2014 à 17:31 michael said : #3

The problem isn't that init doesn't start upower (it never did). It is that from version 0.99.0 on, upower doesn't do suspend/hibernate/etc. anymore (it has been removed in this commit http://cgit.freedesktop.org/upower/commit/?id=1ee642e705a63f5ad56a6b55e4bf5c4a64c959b8 ).

wednesday 23 july 2014 à 17:48 Tanguy said : #4

@michael : Thanks for the precision, I think I already heard that from someone but I forgot it afterwards. Do you know what is supposed to replace UPower for that purpose?

wednesday 23 july 2014 à 17:56 Andrew Shadura said : #5

They say now it's the job of logind.

wednesday 23 july 2014 à 18:59 Philipp Kern said : #6

You mean you get suspend without locking the screensaver? So that's back to the stone age of 2000. We had proper locking since ages.

wednesday 23 july 2014 à 19:15 Tanguy said : #7

@Philipp Kern : So do I, but thank you for supposing I am a fool, it is always a pleasure. By running "xdg-screensaver lock" before "sudo pm-suspend". On my office computer, that is, because I have no reason to lock my home computer the same way.

wednesday 23 july 2014 à 20:47 Steven C. said : #8

Sounds great! It's obviously better than this functionality not working at all. May have to borrow this idea for GNU/kFreeBSD...

wednesday 23 july 2014 à 23:26 Philipp Kern said : #9

My point was that it's not a direct equivalent to what happened before. Applications - like the screensaver or gajim - being able to listen to fact that the machine is being suspended. Nowhere I said that you were a fool, too, albeit I might have been candid.

wednesday 23 july 2014 à 23:55 Tanguy said : #10

@Philipp Kern : I see your point. Well, that is the problem when developers are killing features like that, and we have got to work around it the best we can.

saturday 26 july 2014 à 03:26 Dave said : #11

"systemctl suspend" works for me.

[And thanks for the nice commenting procedure]

thursday 31 july 2014 à 02:13 Clueless said : #12

I litI have this same problem, which led me to your blog. However, I tried:

powerdev ALL=NOPASSWD: /usr/sbin/pm-suspend, \
/usr/sbin/pm-suspend-hybrid, \
/usr/sbin/pm-hibernate

And:

bash: powerdev: command not found


Then I tried:

gpasswd -a [user] powerdev

Which returned:

gpasswd: group 'powerdev' does not exist in /etc/group

I tried gpassswd -a [user] power too. That group does not exist, either.

thursday 31 july 2014 à 09:36 Tanguy said : #13

@Clueless : Well, just create that group then!

monday 12 january 2015 à 03:33 TestDummy said : #14

There is a better way to solve your suspend problem:

monday 12 january 2015 à 03:42 Chris said : #15

You already noticed that UPower has been superseded by Systemd.Logind -- so let's tell logind to do it's job:

<code>
dbus-send --print-reply --system --dest=org.freedesktop.login1 \
/org/freedesktop/login1 org.freedesktop.login1.Manager.Suspend \
boolean:true
</code>

You may also want to take a look at Systemd.Logind documentation for further information, e.g. commands for HybridSleep and Hibernate.

monday 12 january 2015 à 03:43 Christ said : #16

Documentation can be found here:

http://www.freedesktop.org/wiki/Software/systemd/logind/

friday 16 october 2015 à 12:59 Toni said : #17

#Chris #15 works great

Write a comment

What is the fifth letter of the word lvvqve? : 

Archives