除了来自@kyrias的响应之外,这是一种创建自己的用户级别sleep.target的方法:
〜/ .local / share / systemd / user / sleep.target
[Unit]
Description=User level sleep target
StopWhenUnneeded=yes
〜/ .local / bin / watch_sleep
#!/bin/bash
dbus-monitor --system "type='signal',interface='org.freedesktop.login1.Manager',member=PrepareForSleep" | while read x; do
case "$x" in
*"boolean false"*) systemctl --user --no-block stop sleep.target;;
*"boolean true"*) systemctl --user --no-block start sleep.target;;
esac
done
〜/ .local / share / systemd / user / watch_sleep.service
[Unit]
Description=watch for sleep signal to start sleep.target
[Service]
ExecStart=%h/.local/bin/watch_sleep
Restart=on-failure
[Install]
WantedBy=default.target
参见我的博客文章https://medium.com/@aiguofer/systemd-sleep-target-for-user-level-10eb003b3bfd