Stopping an Ubuntu 22.04 desktop from suspending at the login screen

May 26, 2022

We have a little Ubuntu desktop in our machine room to serve as a general access point for system administrators working there (and a machine where you can run a graphical web browser to go look at something, and so on). The other day we deployed a new version of it, replacing the 18.04 version (on very old hardware) with a 22.04 version (on not as old hardware). I was rather unhappy to discover that 20 minutes later, the desktop turned itself off by suspending. This was very much not the desired behavior and finding out how to stop it was not trivial.

If you never want your machine to suspend, sleep, or hibernate for any reason, the modern way to arrange this is to tell systemd to not allow it. This is done through sleep.conf, or more likely a drop in file /etc/systemd/sleep.conf.d/nope.conf, with contents like this:

# Never sleep or hibernate

One advantage of this approach is that a properly operating desktop GUI will recognize this and not even give you the option of trying to suspend, hibernate, or whatever.

If you want to stop the system suspending itself at the login screen, you unfortunately need to know something about how the modern login screen is structured. These days there are two components, a display manager, which is the framework around the graphical login process, and a greeter, which is the part that actually prompts people for their logins. On our 22.04 "desktop" setup (which is actually a server install with various desktop bits added), we were using LightDM as the display manager and the Ubuntu default of Unity Greeter as the greeter. That there are two pieces involved here matters because either or both of the display manager and the greeter can decide to suspend the system when it's idle enough. In order to avoid a suspend at the login screen, you need to get both to stop doing so.

Both the general power behavior and the power behavior of Unity Greeter are controlled through GSettings, although under completely different schemas. Unity Greeter puts its power settings in com.canonical.unity.settings-daemon.plugins.power, while the general settings are in org.gnome.settings-daemon.plugins.power. In both schemas there is a key called 'sleep-inactive-ac-timeout', which is the timeout after which things suspend or act; if set to 0, it's turned off. To specifically disable this 'suspend on idle', you must make sure that both keys have a value of 0. To add more complications, both LightDM and the Unity Greeter actually run as the user lightdm, not as root, so you must change the gsettings for that user.

All of this leads to some very long command lines:

sudo -u lightdm gsettings set com.canonical.unity.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
sudo -u lightdm gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0

On our machine, the general "Gnome" setting was already 0, but the Unity Greeter setting was 1200, matching the 20 minutes from boot to suspend that we saw. I set it to 0 as a precaution, even though we're also disabling suspend globally through systemd.

(Much of this entry come from the Arch wiki's section on disabling suspend, and this askubuntu question and answer, which told me about the gsettings stuff and that I needed to care about both the display manager and the greeter. In theory I could have found the schemas with 'gsettings list-schemas | fgrep power', if I'd realized that this might be hiding out in gsettings.)

PS: Other desktop environments may have versions of this 'on-AC' idle timeout setting. You may wish to do something such as 'gsettings list-recursively | fgrep ac-timeout' to see what turns up for you.

Written on 26 May 2022.
« Shell scripts should be written to be clear first
Modal dialogs and other things that steal keyboard focus are dangerous »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu May 26 22:37:11 2022
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.