How do I disable my system from going to sleep?

Solution 1:

On Ubuntu 16.04 LTS, I successfully used the following to disable suspend:

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target

And this to re-enable it:

sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

From man systemctl:

mask NAME...  
           Mask one or more units, as specified on the command line. This
           will link these unit files to /dev/null, making it impossible to
           start them. This is a stronger version of disable, since it
           prohibits all kinds of activation of the unit, including
           enablement and manual activation. Use this option with care. This
           honors the --runtime option to only mask temporarily until the
           next reboot of the system. The --now option may be used to ensure
           that the units are also stopped. This command expects valid unit
           names only, it does not accept unit file paths.

 unmask NAME...
           Unmask one or more unit files, as specified on the command line.
           This will undo the effect of mask. This command expects valid
           unit names only, it does not accept unit file paths.

Solution 2:

GUI

Have you looked at:

System -> Preferences -> Power Management

On AC Power Tab, Put computer to sleep when inactive for: "Never"

Terminal

Can you open up "gconf-editor"?

Look in: /apps/gnome-power-manager/timeout

Try setting sleep_computer_ac to 0

I'm not positive if anything else needs to be changed as well.

Solution 3:

The right answer for this located here:

Have you tried adding the kernel options acpi=off apm=off to the GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub?

Then run sudo update-grub and reboot your computer.

Solution 4:

None of these described solutions worked for me. The laptop was still going to sleep. Using the Grub Linux command line option of acpi=off caused the laptop to fail to boot. I finally found this solution.

sudo vi /etc/default/acpi-support # and then set SUSPEND_METHODS="none"
sudo /etc/init.d/acpid restart

Based on the original solution from Stephan here: Keep Ubuntu Server running on a laptop with the lid closed?

Solution 5:

In addition to the systemctl mask/unmask options, I also use the following to turn suspend on/off for the Gnome desktop.

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'suspend'
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'suspend'

or

gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'nothing'
gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'

I found these by exploring the settings revealed by the commands listed in How to dump ALL dconf/gsettings so that I can compare them between two different machines?