Ubuntu server wants to take a nap

2024, Dec 21    

Ubuntu server sleeping by default?

Yes, yes it does.

Say it ain’t so. Sorry, I cannot.

I ran into this odd issue recently that started driving me mad.

This all started after I updated an Ubuntu server install and noticed that I couldn’t ping/ssh into the machine anymore. At first I rebooted the server for a quick fix that didn’t end up taking. Approximately 20 minutes later the machine was yet again offline.

I look through the logs quickly and don’t notice anything at first glance. A ticket is opened with the provider and they ask for the root password of the server. This caught me off guard as I knew I was in for a ride. The back and forth was quite annoying and amusing at the same time. I’d send in diagnostics showing it was down and they would respond with diagnostics saying it was up. They even wanted to change the assigned ip at some point.

In the end it was a software issue specific to Ubuntu server that I’ve never seen before.

I always run my servers without a gui (graphical user interface). Apparently for some reason I still cannot determine, a gui was present on this particular server instance. This machine has been happily running with no issues for over a month until this latest update.

Something has changed unbeknownst to me and now the server is having connectivity problems. I did update the machine so the issue is more than likely one of the newly installed packages. Without dumping even more time to solve this exact issue I’ll let this one go. I figure it’s a graphic driver update.

There is a way to vnc into the server so I tried that. I was greeted with a black screen upon connection. Odd behavior I think to myself as I was expecting a console prompt.

A reboot of the server while logging in via vnc shows the familiar booting of an Ubuntu server install. I’m then greeted with a graphic interface. Odd indeed.

At this point it’s getting late and I call it a day. Tomorrow will be the day to check on it.

The machine went offline while I slept and now it’s time to see what the syslog has to tell me.

systemd[1]: Starting System Suspend...
systemd-sleep[2723]: Entering sleep state 'suspend'...

What?! Really?!

Yes really. The machine was going to sleep on an installation of the server edition of Ubuntu! The sleep is essentially crashing the machine gracefully and there appears to be no way for it to exit this state.

Apparently if you install a gui this enables power saving mode and it was set to 20 minutes when navigating through the gui that appears to have been installed.

You can set a machine with a gui installed to boot directly into the console instead of the gui using the following command

sudo systemctl set-default multi-user

This seemed to do the trick for me without needing to go any further.

You can still have the gui enabled but disable power saving by disabling different sleep functions. The following will work regardless as you are directly disabling these power saving functions.

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

If you want to revert it back you can unmask it.

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

Once masked you should have a similar output for each part.

sleep.target
     Loaded: masked (Reason: Unit sleep.target is masked.)
     Active: inactive (dead)

On my machines without any gui/window managers they look like the following.

systemctl status sleep.target

sleep.target - Sleep
     Loaded: loaded (/lib/systemd/system/sleep.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

This is a first for me. Normally having a no gui install is the default install for me. You save precious resources especially on lower end machines as I have no need for a gui when doing work on the command line. I’m wondering if these default operating system installs on certain vps hosts install the gui by default? Perhaps I didn’t pay close enough attention in the installation process? Why was this machine running fine for a month until now?

Who knows.

All I know is that this nugget of information will occupy another region of my brain. I still wonder why a gui install would enable power saving like this on a server. The last thing I want is my 24/7 server to sleep.

At least I eventually got some sleep myself after this ordeal.