如何使用 systemd 在挂起时停止 Clementine 播放

如何使用 systemd 在挂起时停止 Clementine 播放

我试图在进入挂起模式之前使用 DBus 停止 Clementine 播放。这是我现在的服务文件:

[Unit]
Description=Stop Clementine playback before suspend
Requires=dbus.service
Before=sleep.target
Before=dbus.service

[Service]
User=jo
Type=oneshot
ExecStart=-/bin/sh -c 'qdbus org.mpris.clementine /Player org.freedesktop.MediaPlayer.Stop'

[Install]
WantedBy=sleep.target

现在,这有效了,即播放已停止。然而,systemd 随后需要很长时间才能真正进入挂起模式。查看journalctl中的日志,我看到:

Jun 05 23:43:53 localhost.localdomain systemd[1]: Starting Suspend...
Jun 05 23:44:18 localhost.localdomain systemd-sleep[7052]: Error: org.freedesktop.DBus.Error.NoReply
Jun 05 23:44:18 localhost.localdomain systemd-sleep[7052]: Did not receive a reply. Possible causes include: the remote application did not send a reply, the 
Jun 05 23:44:18 localhost.localdomain systemd-sleep[7052]: Suspending system...

我的第一个想法是 DBus 系统,或者 Clementine 本身在有时间回复之前就被挂起,从而导致挂起。这就是为什么我尝试在上面的服务文件中添加对 dbus 服务的依赖项。然而,这并不能解决问题。

有任何想法吗?

相关内容