jlm-blog
~jlm

19-Jun-2012

Stopping laptop suspend on Ubuntu Linux

Filed under: linux — jlm @ 21:15

The default configuration for Ubuntu is to suspend the laptop any and every time the lid is closed, regardless of whether it’s on AC power or using an external display and keyboard, which is pretty annoying but up until Oneiric the setting wasn’t too difficult to discover and override. With Oneiric, Ubuntu reset the suspend options during the upgrade and removed it from GUI accessibility (Options are bad! Everyone uses computers the same way! No one uses an external KVM with a laptop! Gag.), but 5 seconds of web search reveals how to set it with the command line: gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing

Except one problem. This only affects the PM settings if you’re logged in to the primary X console. I also want to be able to use my laptop headless. What to do when not logged in was set under “system” (as opposed to “user”) options in the no-longer-available GUI, but no references I found told how to set it from the command line. This is done by running gsettings set as a system user unsurprisingly, but unfortunately, gsettings doesn’t work from sudo or su, because gsettings wants to start up dbus because … I don’t know why. And it won’t run without X, and gsettings won’t run without dbus. So, how do you run something non-graphical with dbus access? That turns out to be with the dbus-launch command, which can figure out it’s not in X unlike whatever gsettings is doing to start dbus, so what we want is sudo dbus-launch gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing

Ha ha, no. That changes the setting for the root user, but the laptop still suspends. This turns out to be because the settings used when awaiting login aren’t root’s, but gdm’s. So that means to stop the suspending, we do sudo -u gdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing

Ha ha, no. See, the documentation on whose settings are used is wrong. It’s not gdm’s settings that are used at all. (That’s whose was used up to Natty.) If you look at your passwd file, you’ll see there’s a new display-manager user in addition to gdm now: lightdm. What the docs don’t say is that it’s that user whose settings are used now. So, no more teasing, this is the command which keeps your laptop powered on: sudo -u lightdm dbus-launch gsettings set org.gnome.settings-daemon.plugins.power lid-close-ac-action nothing

1 Comment

  1. Thank you very much man!

    I’ve been trying to stop the damn suspension without success for days and I finally found your post!

    This freaking this should work without a hassle!

    Comment by John Doe — 23-Jul-2012 @ 18:50

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress