On Debian and Ubuntu operating systems with a graphical user interface, the sleep (suspend) and hibernation modes are enabled by default.
Suspend mode allows you to save power and extend battery life when the device is not in use. To wake up the device from sleep mode, you will need to click with the mouse or press any key on the keyboard. However, on some devices, the only way to wake the operating system from sleep is to press the power button.
The history of Ubuntu/Debian entering sleep mode can be viewed in the system log:
$ journalctl | grep systemd-sleep
Run the following command to suspend your device manually:
$ sudo systemctl suspend
Check that hibernation and sleep are enabled on your computer:
$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
The command returns the following status for systemd daemons when suspend is enabled:
○ sleep.target - Sleep
Loaded: loaded (/lib/systemd/system/sleep.target; static)
Active: inactive (dead)
Docs: man:systemd.special(7)
To turn off both sleep and hibernation:
$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
If you now check the status of the suspend mode, the command will return:
○ sleep.target
Loaded: masked (Reason: Unit sleep.target is masked.)
Active: inactive (dead)
To re-enable suspend and hibernation:
$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
You can disable suspend when closing the lid on Ubuntu/Debian laptops.
Edit the file /etc/systemd/logind.conf:
$ sudo nano /etc/systemd/logind.conf
Add the lines to the file:
[Login]
HandleLidSwitch=ignore
HandleLidSwitchDocked=ignore
Apply the new settings:
$ sudo systemctl restart systemd-logind.service
You can also disable sleep and hibernation modes by creating a file:
$ sudo nano /etc/systemd/sleep.conf.d/nosuspend.conf
[Sleep]
AllowSuspend=no
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no