Ubuntu Server Freezes After Several Minutes

After upgrading Ubuntu 20.04 LTS to Ubuntu 22.04LTS, the server always freezes after ~10 minutes. All services are down, cannot ssh, connect to serial console but cannot input. However, this issue never happen before release upgrade.

After hard reboot, I tried to find clue in logs.

journalctl -xe has no related error messages.

Then I browse syslog around the server freeze time by less /var/log/syslog and found something interesting:

Apr 17 23:32:08 user NetworkManager[1057]: <info>  [1713367928.2254] manager: sleep: sleep requested (sleeping: no  enabled: yes)
Apr 17 23:32:08 user systemd[1]: Reached target Sleep.
Apr 17 23:32:08 user systemd[1]: Starting Record successful boot for GRUB...
Apr 17 23:32:08 user systemd[1]: Starting System Suspend...
Apr 17 23:32:08 user gnome-shell[1875]: Screen lock is locked down, not locking
Apr 17 23:32:08 user systemd[1]: grub-common.service: Deactivated successfully.
Apr 17 23:32:08 user systemd[1]: Finished Record successful boot for GRUB.
Apr 17 23:32:08 user systemd[1]: Starting GRUB failed boot detection...
Apr 17 23:32:08 user systemd-sleep[2313]: Entering sleep state 'suspend'...

Seems that the server automatically go to sleep after 10 minutes when idle. Although I never use GUI (ssh console only), I guess the issue is caused by gnome desktop. The release upgrade automatically install gnome which suspends the system when idle.

The solution is easy, just remove all gnome related packages:

$ sudo apt remove gnome*

It would be better to disable suspend and hibernate in systemd, but I didn't do it.

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