Ubuntu 如果插上显示器不使用,一段时间(通常是 20 分钟)后会突然停了。

目前我主要方案是这个: https://www.unixtutorial.org/disable-sleep-on-ubuntu-server/

主要信息:

禁止:

$ 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.

恢复:

$ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
Removed /etc/systemd/system/sleep.target.
Removed /etc/systemd/system/suspend.target.
Removed /etc/systemd/system/hibernate.target.
Removed /etc/systemd/system/hybrid-sleep.target.

上面主要做法是把那几个 sleep, suspend, hibernate, hybrid-sleep 行为禁止掉了。


另外,考虑是不是装 Nvidia Driver 的时候不小心装上了 gnome 的缘故,所以做了如下设置。但是似乎不工作。

当前用户检查电源管理 sleep-inactive-ac-timeout 设置:

$ gsettings get org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout
1200

疑似这个就是原因。

修改成这样:

$ gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0

查看目前所有选项如下:

$ gsettings list-recursively org.gnome.settings-daemon.plugins.power
org.gnome.settings-daemon.plugins.power lid-close-ac-action 'suspend'
org.gnome.settings-daemon.plugins.power time-critical 300
org.gnome.settings-daemon.plugins.power power-button-action 'suspend'
org.gnome.settings-daemon.plugins.power lid-close-suspend-with-external-monitor false
org.gnome.settings-daemon.plugins.power button-hibernate 'hibernate'
org.gnome.settings-daemon.plugins.power idle-dim true
org.gnome.settings-daemon.plugins.power button-power 'suspend'
org.gnome.settings-daemon.plugins.power lid-close-battery-action 'suspend'
org.gnome.settings-daemon.plugins.power priority 0
org.gnome.settings-daemon.plugins.power idle-brightness 30
org.gnome.settings-daemon.plugins.power active true
org.gnome.settings-daemon.plugins.power critical-battery-action 'hibernate'
org.gnome.settings-daemon.plugins.power button-suspend 'suspend'
org.gnome.settings-daemon.plugins.power button-sleep 'hibernate'
org.gnome.settings-daemon.plugins.power percentage-critical 3
org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 0
org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'suspend'
org.gnome.settings-daemon.plugins.power ambient-enabled true
org.gnome.settings-daemon.plugins.power notify-perhaps-recall true
org.gnome.settings-daemon.plugins.power percentage-low 10
org.gnome.settings-daemon.plugins.power percentage-action 2
org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'suspend'
org.gnome.settings-daemon.plugins.power time-low 1200
org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 1200
org.gnome.settings-daemon.plugins.power time-action 120
org.gnome.settings-daemon.plugins.power use-time-for-policy true

参考 https://ubuntu-mate.community/t/ubuntu-mate-auto-suspend-20-minutes-after-it-restart/17650

效果并没有变化,停止前 log 依然是,然后卡住。

Nov 24 18:50:09 diony NetworkManager[863]: <info>  [1637751009.5098] manager: sleep: sleep requested (sleeping: no  enabled: yes)
Nov 24 18:50:09 diony ModemManager[934]: <info>  [sleep-monitor] system is about to suspend
Nov 24 18:50:09 diony NetworkManager[863]: <info>  [1637751009.5100] manager: NetworkManager state is now ASLEEP
Nov 24 18:50:09 diony gnome-shell[1286]: Screen lock is locked down, not locking
Nov 24 18:50:09 diony systemd[1]: Reached target Sleep.
Nov 24 18:50:09 diony systemd[1]: Starting Record successful boot for GRUB...
Nov 24 18:50:09 diony systemd[1]: Starting Suspend...
Nov 24 18:50:09 diony systemd-sleep[18784]: Suspending system...
Nov 24 18:50:09 diony kernel: [ 1221.038239] PM: suspend entry (deep)
Nov 24 18:50:09 diony systemd[1]: grub-common.service: Succeeded.
Nov 24 18:50:09 diony systemd[1]: Finished Record successful boot for GRUB.
Nov 24 18:50:09 diony systemd[1]: Starting GRUB failed boot detection...
Nov 24 18:50:09 diony systemd[1]: grub-initrd-fallback.service: Succeeded.
Nov 24 18:50:09 diony systemd[1]: Finished GRUB failed boot detection.
Nov 24 18:50:09 diony kernel: [ 1221.097020] Filesystems sync: 0.058 seconds
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (**) Option "fd" "40"
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) event2  - Power Button: device removed
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (**) Option "fd" "43"
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) event1  - Power Button: device removed
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (**) Option "fd" "44"
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) event0  - Sleep Button: device removed
Nov 24 18:50:10 diony kernel: [ 1221.728849] snd_hda_codec_hdmi hdaudioC1D0: HDMI: invalid ELD data byte 0
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) systemd-logind: got pause for 13:65
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) systemd-logind: got pause for 13:64
Nov 24 18:50:10 diony /usr/lib/gdm3/gdm-x-session[1242]: (II) systemd-logind: got pause for 13:66

此外,还考虑这个:https://ubuntuhandbook.org/index.php/2020/05/lid-close-behavior-ubuntu-20-04/

主要是编辑 /etc/systemd/logind.conf 这个文件。 这个文件原文是:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See logind.conf(5) for details.

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192

#HandleLidSwitch=suspend 一行修改行为:

  • HandleLidSwitch=lock – 合盖即锁定
  • HandleLidSwitch=ignore – 合盖即什么都不做
  • HandleLidSwitch=poweroff – 合盖即关机
  • HandleLidSwitch=hibernate – 合盖即进入 hibernate 待机状态

当然出于时间考虑直接 mask 掉这几个行为,对目前我的机器而言应该都一样(任何时候都不关机,除非主动手动关)

Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

Leave a Reply

Your email address will not be published. Required fields are marked *