什么实际上可以触发 systemd 目标单元(例如 suspend.target)的活动状态?

什么实际上可以触发 systemd 目标单元(例如 suspend.target)的活动状态?

我正在随机进入休眠状态的服务器我不知道到底是什么触发器系统日志中的该状态。

因此我的问题是:在 Ubuntu 22.04 上,什么过程或事件能够真正触发以下systemd目标的状态进入某种active状态(例如使系统进入睡眠状态)?

$ systemctl status suspend.target 
○ suspend.target - Suspend
     Loaded: loaded (/lib/systemd/system/suspend.target; static)
     Active: inactive (dead)
       Docs: man:systemd.special(7)

答案1

那将是

systemctl enable suspend.target 

请注意,enable如果系统服务出现故障,将会出错,并显示以下内容:

$ systemctl enable suspend.target 
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.
 
Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.

如果这样,要启用它...首先需要修复该问题。

答案2

据我所知,省电会触发它。阅读后,man systemd.special您会发现它suspend.target会拉动sleep.target,并在需要时调用。

   suspend.target
       A special target unit for suspending the system. This pulls in
       sleep.target.
   sleep.target
       A special target unit that is pulled in by suspend.target,
       hibernate.target and hybrid-sleep.target and may be used to hook
       units into the sleep state logic.

Special System Units它是系统服务管理器管理的一部分。

运行systemctl start systemd-suspend.service将使您的系统立即进入睡眠状态,因为它现在处于活动状态,因此它必须保持不活动状态直到需要它为止。

答案3

我也遇到过同样的情况:

systemctl status systemd-suspend
● systemd-suspend.service - Suspend
     Loaded: loaded (/lib/systemd/system/systemd-suspend.service; static; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:systemd-suspend.service(8)

幸运的是,当我浏览这个页面时,我有了一个想法。

用于journalctl -b -1 -u systemd-*检查:

10月 20 15:05:36 HOSTNAME systemd-logind[830]: Suspend key pressed.
10月 20 15:05:36 HOSTNAME systemd-logind[830]: Suspend key pressed.
10月 20 15:05:38 HOSTNAME systemd[1]: Starting Suspend...
10月 20 15:05:38 HOSTNAME systemd-sleep[442813]: Suspending system...

这是什么Suspend key pressed意思?

按下键盘上的电源键。 https://docs.oracle.com/cd/E19620-01/805-5233/z400162db17/index.html

结论:你可能不小心按到了键盘上的挂起键。即使你禁用了挂起服务,它也会挂起你的服务器。按下电源按钮可以恢复。这是除了重启之外唯一恢复的方法。

相关内容