![什么实际上可以触发 systemd 目标单元(例如 suspend.target)的活动状态?](https://linux22.com/image/949446/%E4%BB%80%E4%B9%88%E5%AE%9E%E9%99%85%E4%B8%8A%E5%8F%AF%E4%BB%A5%E8%A7%A6%E5%8F%91%20systemd%20%E7%9B%AE%E6%A0%87%E5%8D%95%E5%85%83%EF%BC%88%E4%BE%8B%E5%A6%82%20suspend.target%EF%BC%89%E7%9A%84%E6%B4%BB%E5%8A%A8%E7%8A%B6%E6%80%81%EF%BC%9F.png)
我正在随机进入休眠状态的服务器我不知道到底是什么触发器系统日志中的该状态。
因此我的问题是:在 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
结论:你可能不小心按到了键盘上的挂起键。即使你禁用了挂起服务,它也会挂起你的服务器。按下电源按钮可以恢复。这是除了重启之外唯一恢复的方法。