How To: Disable Sleep/Hibernation on Ubuntu Server

In an earlier article, I wrote about making my own router. I am currently using Ubuntu’s server release for this. Imagine my surprise when I discovered a server configured to sleep! 

Rather than try to figure out why a server would sleep by default, I’m just going to concentrate on fixing it. Seriously, though. Who decided to include all the sleep and hibernation underpinnings and decided they should be on by default? I can absolutely assure you that I did not turn them on!


Seriously! My log contained lovely hints like:

[code]Apr 3 12:18:27 server systemd[1]: Reached target Sleep.[/code]

Disable Power Management – Ubuntu Server

This time you probably don’t need to open a terminal. It’s a server! Use SSH and you’re already in a terminal! Sheesh!

Anyhow, to make sure that this doesn’t happen again, let’s go ahead and kill everything that has to do with suspend, sleep, or hybrid-sleep. It’s actually pretty easy.

Let’s start with ‘sleep.target’ and we’re going to just mask these rather than removing them. If we mask them, we can unmask them – should we ever feel the need to do so, though I can’t see why you’d want them with server applications.

[code]sudo systemctl mask sleep.target[/code]

Next, let’s take care of ‘suspend.target’ with:

[code]sudo systemctl mask suspend.target[/code]

Then we’ll take care of ‘hibernate.target’ with:

[code]sudo systemctl mask hibernate.target[/code]

And, last but not least, we will go ahead and mask ‘hybrid-sleep.target’:

[code]sudo systemctl mask hybrid-sleep.target[/code]

As alluded to above, you can undo any of those by simply changing ‘mask’ to ‘unmask’ in the commands above and it will re-enable them. Why you’d want to do that, I have no idea – just like I have no idea why these things would even be included in a server-specific release, never mind why any of them would be enabled!

If you’re feeling so inclined, you can verify they’re off. For example, ‘sleep.target’ can be checked with:

[code]systemctl status sleep.target[/code]

Finally, thanks for reading. Like always, I love the feedback and the newsletter is still there waiting for you to sign up. If you do sign up, I chose a pretty crappy domain name and you should probably check your spam inbox for the confirmation email.