最近在升级到ubuntu 20.04
桌面版之后,发现当登陆之后,如果系统较长时间不操作,系统就自动休眠了。
如果重启之后,从来都没有登陆,就不会出现系统自动休眠的情况。
观察系统日志,发现类似如下的内容:
1 2 3 4 5 6 7 8 |
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... |
发现是触发了systemd
的自动休眠功能,检查休眠功能的状态以及历史记录,如下:
1 2 3 4 5 6 7 8 9 |
$ systemctl status sleep.target ● sleep.target - Sleep Loaded: loaded (/lib/systemd/system/sleep.target; 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. |
普通桌面应用这个情况问题不大,但是如果是作为服务器使用的时候,我们一般远程访问系统,这个功能就会导致我们无法远程控制服务器,因此我们需要关闭这个功能。
执行关闭休眠功能的命令,如下:
1 2 3 4 5 |
$ sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target Created symlink /etc/systemd/system/sleep.target → /dev/null. Created symlink /etc/systemd/system/suspend.target → /dev/null. Created symlink /etc/systemd/system/hibernate.target → /dev/null. Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null. |
再次观察系统休眠状态,如下:
1 2 3 4 |
$ systemctl status sleep.target ● sleep.target Loaded: masked (Reason: Unit sleep.target is masked.) Active: inactive (dead) |
发现自动休眠功能已经被关闭,不会出现自动休眠导致远程控制无法访问的情况了。