141

I am getting a web server setup at home on an older AMD 2400+ desktop. I have Ubuntu 11.04 installed and running however, after a time, I can no longer browse to the server. When I go to the keyboard and press a key, everything magically works again.

I have looked through the BIOS and I am not seeing any power saving features enabled. Is there anything like that in Ubuntu? Can it be disabled?

I don't have any GUI installed. This is console only.

gosuto
  • 175
  • 1
  • 6
Mike Wills
  • 1,693

8 Answers8

157

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.
abu_bua
  • 10,783
  • 5
    How would I test whether these are or aren't masked already? (And what does mask or unmask do anyways? Never heard of those before.) – ArtOfWarfare Sep 15 '17 at 00:53
  • 1
    @ArtOfWarfare From man systemctl "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." – Centimane Oct 24 '17 at 18:17
  • 1
    @Centimane - Thanks. So how would I actually check if they already were masked or not? Obviously I could try just running them and see what happens, but that would potentially cause the side effect of putting my computer to sleep (which would be... bad... it has issues waking up, which is why I want to just ensure it never sleeps.) – ArtOfWarfare Oct 24 '17 at 19:33
  • @ArtOfWarfare you could just check /etc/systemd/system/ for a link to /dev/null – Centimane Oct 24 '17 at 19:38
  • 1
    @ArtOfWarfare or systemctl show -p FragmentPath [service]. The FragmentPath property tells you where systemd thinks the unit file lives. A masked service will say /dev/null – Centimane Oct 24 '17 at 19:41
  • 4
    This worked for me, but had the side effect of bringing the CPU to 70-100% indefinitely whenever I closed the lid, because the system service systemd-logind was trying to execute the suspend service but couldn't. The solution is to ignore the lid with HandleLidSwitch=ignore in /etc/systemd/logind.conf – Djizeus Jun 08 '19 at 22:17
  • Any way to do this without root privileges? – ed22 Aug 27 '19 at 07:58
  • 1
    Really sorry to revive this ancient thread, just to comment on the suggested solution. If you mask out hibernation, you will not be able to put the system into hibernation manually either. I.e. select it from the start menu etc. This is a real downside. Power management settings don't always appear to work - my dell laptop seems to go into hibernation whenever it feels like it, and to h*ll with any power management settings. – user1283068 Nov 06 '20 at 15:05
  • @ArtOfWarfare Does the mask [service] persist across reboots, or must this be remasked after a reboot? – alabamatoy Mar 17 '21 at 12:19
  • 1
    'sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target'

    explicity lists the targets (suspend, etc) as masked

    – Tom Russell Mar 29 '21 at 19:46
  • @Djizeus's comment in underrated. In my case systemd-logind spammed my /var/log/auth.log until it filled the disk. MASKING IS NOT THE WAY TO GO! – gosuto Aug 01 '21 at 09:28
  • Also works on Ubuntu 20.04 – not2savvy Jun 30 '22 at 12:39
38

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.

  • 2
    How do I do that on the console? I don't have a gui installed. – Mike Wills Jun 06 '11 at 20:17
  • @Mike Wills Updated since you have no gui – Jason Iverson Jun 06 '11 at 20:41
  • 2
    Again, I don't have gnome or any of that installed. It is a pure console. – Mike Wills Jun 07 '11 at 01:47
  • 18
    Up to date command-line way is: gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout '0' && gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout '0' – dess Jul 22 '15 at 11:45
  • 2
    @dess very helpful. Thanks! You should post your response in an answer for others to see. – kalu Jan 12 '16 at 22:59
  • Note that on Xubuntu you must drag the slider to the far left (which is counter-intuitive), to get to the "never" option. Dragging to the right maxes out at a max delay time for suspend of 5 hrs 50 min, so drag far left to get "never." – Gabriel Staples Sep 05 '16 at 21:41
  • @dess , is this permanent or until session ends? – ed22 Aug 27 '19 at 08:06
  • @ed22 , it's GSettings, so it's permanent in common case. – dess Aug 27 '19 at 15:48
  • I went to Settings -> Power -> Automatic Suspend -> Off and I can now ssh into my desktop after locking the screen. –  Nov 11 '20 at 06:34
  • How is this upvoted? This does not answer the question for someone who has no GUI. @MikeWills stated clearly - several times - that there is NO GUI INSTALLED. That means there is no gsettings. There is no /apps/gnome-power-manager. Because gnome is not installed. – klugerama Feb 06 '21 at 03:35
  • @klugerama the one that I marked as the answer likely worked. But that was my frustration at the time. – Mike Wills Feb 07 '21 at 04:30
  • Its doesnt worked, i disabled sleep, but after inactivity 3-4 or more hours, computer did sleep. – CETb Mar 13 '23 at 01:54
19

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?

Andrew Vian
  • 537
  • 4
  • 6
  • 1
    I'm aware that I'm commenting on a posting that is 5 years old by now. With that disclaimer over, please note that the acpi-support package has been deprecated for a while and is now gone. In my particular system, I still have acpid. If you want to see what acpid has to say, try setting OPTIONS="-d -l" (that's a lowercase L) in /etc/default/acpid to produce some output in the syslog i.e. /var/log/daemon log or some such. – frr Nov 05 '21 at 19:02
14

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.

Mike Wills
  • 1,693
  • 7
    Whilst adding these options to my grub configuration did stop my machine from going to sleep, it should be noted setting acpi=off has a lot of other effects. The key one for me is that it also disables hyperthreading. – PicoutputCls Feb 21 '19 at 17:33
  • 1
    @PicoutputCls the artice you link states that acpi=ht "Deactivates the ACPI system almost completely; only the components required for hyper threading will be used" – pzkpfw Aug 01 '19 at 07:49
  • The whole system becomes very slow if I set acpi=off – GummyBear21 Aug 13 '19 at 02:32
  • this setting caused my laptop/ubuntu 20.02 to being restarting at random times. Use with caution. – FlyingZebra1 Jul 10 '21 at 23:40
  • 1
    On systems with ACPI, ACPI is the preferred way of setting up IRQ routing and initiallizing SMP (multi-CPU / multi-core stuff) during OS boot. If you disable ACPI, chances are, that the APIC's and multiple CPU cores can start up via the older (pre-ACPI) MPS BIOS services, if these are present in the BIOS and in good shape. Otherwise, disabling ACPI may constrain your system to a single CPU core and just the ~15 legacy IRQ's, which will be massively shared by the myriad devices in a modern PC system. I.e. acpi=off can indeed result in a slow or non-booting system. – frr Nov 05 '21 at 19:13
10

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?

HankB
  • 265
8

Please try looking into these links - cyberciti.biz and Arch forums

This is an excerpt from the cyberciti.biz link:

By default, the Linux kernel will use screen-save option to disable it you need to type this command (it turns off monitor VESA powersaving features):

$ setterm -powersave off -blank 0

If it dumps back you with an error that read as follows: cannot (un)set powersave mode

You need to shutdown X window system and rerun the above command. Better, add following two commands to your ~/.xinitrc file:

setterm -blank 0 -powersave off -powerdown 0
xset s off
7

Just wanted to note my problems with the accepted answer and provide an alternative solution:

Masking sleep.target, suspend.target etc. using systemctl does do the job, but know that systemd-logind will still try to call sleep.target (or which ever)!

@Djizeus reports that this resulted in an indefinite CPU usage of 70-100% after closing the lid. Personally I experienced systemd-logind spamming my /var/log/auth.log until it filled the disk (tens and tens of lines per second reporting sleep is masked).

Taken again from @Djizeus' comment: "[t]he solution is to ignore the lid with HandleLidSwitch=ignore in /etc/systemd/logind.conf".

gosuto
  • 175
  • 1
  • 6
  • 3
    I second that. And, as I'm prevented from posting here (being a noob), here goes my counter-suggestion: edit /etc/systemd/sleep.conf ; AllowSuspend=no , AllowHibernation=no . See also man systemd-sleep , man systemd-sleep.conf . – frr Nov 05 '21 at 19:15
0

I found Light Locker, as I have Ubuntu 14.04.2 with LXDE (Lubuntu) Desktop; if you have this desktop you can change the default and manage the monitor through that. Otherwise you might have to install gconf-editor through terminal if you don't have it. Light Locker is in can be found in Preferences in the main menu.