%20%E4%B8%8A%E5%81%9C%E7%94%A8%E6%8E%9B%E8%B5%B7.png)
我有一台安裝了 ubuntu 20.04 的筆記型電腦,用作伺服器。因此我希望它永遠不會暫停。
預設情況下,當蓋子關閉時,它會自動暫停。
由於我只能透過 ssh 存取它(並且無論如何都沒有安裝 X),所以我需要透過 CLI 來停用它。
多個網站建議使用
sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
這確實可以防止筆記型電腦在蓋子關閉時掛起,但會導致 systemd-logind 消耗 100% cpu 並連續記錄以下內容:(每秒多次)
systemd-logind[514]: Suspending...
systemd-logind[514]: Unit suspend.target is masked, refusing operation.
systemd-logind[514]: Failed to execute suspend operation: Permission denied
誰能告訴我怎麼做適當地禁用暫停?
答案1
經過一番搜索,我找到了正確的答案:
在/etc/systemd/logind.conf
底部加入以下行:
HandleSuspendKey=ignore
HandleHibernateKey=ignore
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
並運行
systemctl restart systemd-logind
啟動新設定。