How To: Disable Sleep on Ubuntu Server

Ubuntu 19.10 Ubuntu 19.10

You may remember that I have a small automation server in my home office that’s running Ubiquiti UniFi Controller software and where I upgraded UniFi Controller on Ubuntu 19.04.

I noticed that this server hasn’t been terribly available since upgrade to Ubuntu 19.04: more than once I went looking for the server and it was offline.

Now that I’m finally progressing with centralized RSyslog setup at home, I noticed that the UniFi controller server was reporting the following in logs recently:

Feb 25 22:15:38 server NetworkManager[737]: <info>  [1582668938.0193] manager: sleep: sleep requested (sleeping: no  enabled: yes)
Feb 25 22:15:38 server NetworkManager[737]: <info>  [1582668938.0239] manager: NetworkManager state is now ASLEEP
Feb 25 22:15:38 server whoopsie[1025]: [22:15:38] offline
Feb 25 22:15:38 server gnome-shell[956]: Screen lock is locked down, not locking
Feb 25 22:15:38 server systemd[1]: Reached target Sleep.
Feb 25 22:15:38 server systemd[1]: Starting Suspend...
Feb 25 22:15:38 server kernel: [ 1235.212537] PM: suspend entry (s2idle)
Feb 25 22:15:38 server systemd-sleep[1705]: Suspending system...

So, it appears the power management has improved enough to start bringing this server to sleep every hour or so.

Since this is a recent enough version of Ubuntu, I figured there should be a way to disable power management using systemctl. Turns out, there is.

Confirm Sleep Status with systemd

IMPORTANT: I didn’t run this command on server, so this is example from another system: I’m running it on my XPS laptop with Ubuntu, just to show you expected output.

As you can see, my laptop rests well and often:

[email protected]:~ $ systemctl status
 ● - Sleep
    Loaded: loaded (/lib/systemd/system/; static; vendor preset: enabled)
    Active: inactive (dead)
      Docs: man:systemd.special(7)
 Feb 24 13:18:08 xps systemd[1]: Reached target Sleep.
 Feb 26 13:29:31 xps systemd[1]: Stopped target Sleep.
 Feb 26 13:29:57 xps systemd[1]: Reached target Sleep.
 Feb 26 13:30:19 xps systemd[1]: Stopped target Sleep.

Disable Sleep in Ubuntu with systemd

This is what I did on my server:

[email protected]:/ # sudo systemctl mask
 Created symlink /etc/systemd/system/ → /dev/null.
 Created symlink /etc/systemd/system/ → /dev/null.
 Created symlink /etc/systemd/system/ → /dev/null.
 Created symlink /etc/systemd/system/ → /dev/null.
 [email protected]:/etc/pm/sleep.d#

This is obviously a very simple way of disabling power management, but I like it because it’s standard and logical enough – there’s no need to edit config files or create cronjobs manually controlling sleep functionality.

The service is dead, no power management is happening and most importantly, my server has been up for 12 hours now.

[email protected]:~$ systemctl status
   Loaded: masked (Reason: Unit is masked.)
   Active: inactive (dead)

(re) Enabling Sleep in Ubuntu with systemctl

When the time comes and I would like to re-enable power management and sleep/hibernation, this will be the command I’ll run:

[email protected]:/etc/pm/sleep.d# sudo systemctl unmask

That’s all for now. Have a great day!

See Also

Keep Learning with Me

Follow me on Facebook and Twitter or jump into Telegram chat!:
Recommended Software
I use Brave browser, it's awesome: Brave Browser I'm also a fan of SetApp for macOS: SetApp for macOS
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets