How to prevent Ubuntu Server sleep/hibernation

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?


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:

Try using

setterm -blank 0

It needs to be entered after every boot, but keeps things running.

Solution 3:

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.