Stopping my Ubuntu server from hibernating

I’m not sure what’s happened, but after a recent upgrade to my Ubuntu server – when I tried to connect to the server (which I use as both a dev server and NAS), I couldn’t log into via ssh but when I attached a monitor and keyboard to the server I was able to use it and the ssh started working. However after a period of inactivity the server seemingly went offline, pressing the power switch briefly bought it back online. So some how it had gone sleep/hibernate mode – not very useful thing for a server.

Here’s some steps I went through to eventually get this working again…

Check the logs

Checking the logs is always a useful first step, so let’s take a look at the syslog

nano /var/log/syslog

or use

tail -f /var/log/syslog

I spotted log entries saying the machine was going to sleep.

Checking and then disabling sleep mode

Now use systemctl to confirm the status of the sleep.target, i.e. is it enabled

sudo systemctl status sleep.target

To disable sleep, we probably want to disable all options that hibernate/sleep so we can disable the lot using

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

If for some reason you wish to re-enable these, just run

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

I’m still none the wiser as to how hibernate got enabled – but at least I’ve learned how to check and disable it.