如何透過 CLI 在 Ubuntu 20.04 (systemd) 上停用掛起

如何透過 CLI 在 Ubuntu 20.04 (systemd) 上停用掛起

我有一台安裝了 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

啟動新設定。

相關內容