How to prevent Ubuntu Server sleep/hibernation

16,548

Solution 1

I understand this is an old post, but I had this same problem and had a hard time finding a decent answer.

My laptop with Ubuntu Server would go into a white screen saver, and soon after everything would lose connection to the server. As soon as I exited the screen saver with the keyboard on the laptop, everything was able to once again connect. The acpi=off, setterm -blank 0, and other options described on similar questions never worked, until I found a working answer from the Unix and Linux SE.

After this solution, my laptop still goes to the white screen saver, however I no longer lose connection to any of the services running on it (SSH, SFTP, HTTP).

This command disables suspend:

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

and this command brings it back:

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

Solution 2

You might try Caffeine. You can either use the 'caffeinate' command to prevent your server from sleeping during a given commmand (see http://www.webupd8.org/2015/01/caffeine-app-gets-its-indicator-back.html for syntax) or just set it to prevent idle all the time.

Share:
16,548

Related videos on Youtube

Trent
Author by

Trent

Updated on September 18, 2022

Comments

  • Trent
    Trent almost 2 years

    I'm running the latest Ubuntu Server (quite literally downloaded & installed yesterday) on a box under my desk. I've got trac installed and OpenSSH. Intermittently both become unavailable, as if the server has gone to sleep, which seems odd because to me, the whole idea of a server is that it's always on/available.

    The server is only used on the LAN.

    I've tried adding acpi=off to /etc/default/grub, running update and rebooting, no difference.

    Currently, I have SSH open and if I leave it for some time, it will remain connected, but lag horribly when I go back to using it. Last time this sleep/hibernate issue happened, I had to plug in a keyboard and monitor to get it come back up.

    Any ideas or suggestions?

  • Fabby
    Fabby about 9 years
    Although your answer is 100% correct, it might also become 100% useless if that link is moved, changed, merged into another one or the main site just disappears... :-( Therefore, please edit your answer, and copy the relevant steps from the link into your answer, thereby guaranteeing your answer for 100% of the lifetime of this site! ;-) You can always leave the link in at the bottom of your answer as a source for your material...
  • Rodrigo
    Rodrigo over 8 years
    Why install a third party software to do what setterm -blank 0 already does?