使用 systemd 激活锁屏不起作用

使用 systemd 激活锁屏不起作用

我尝试betterlockscreen在每次关闭笔记本电脑时使用此 systemd 服务文件来激活它:

[Unit]
Description = Lock screen when going to sleep/suspend
Before=sleep.target
Before=suspend.target

[Service]
User=%I
Type=simple
Environment=DISPLAY=:0
ExecStart=/usr/local/bin/betterlockscreen --lock
TimeoutSec=infinity
ExecStartPost=/usr/bin/sleep 1   

[Install]
WantedBy=sleep.target
WantedBy=suspend.target

当我跑步时systemctl status betterlockscreen@$USER我看到

[email protected] - Lock screen when going to sleep/suspend
     Loaded: loaded (/lib/systemd/system/[email protected]; enabled; vendor preset: enabled)
     Active: inactive (dead) since Wed 2022-09-21 20:49:58 CEST; 3h 28min ago
   Main PID: 168557 (code=exited, status=0/SUCCESS)
        CPU: 763ms

Sep 21 20:33:18 tom-ThinkPad-X1-Carbon-Gen-9 systemd[1]: Starting Lock screen when going to sleep/suspend...
Sep 21 20:33:18 tom-ThinkPad-X1-Carbon-Gen-9 betterlockscreen[168557]: [B] Betterlockscreen
Sep 21 20:33:18 tom-ThinkPad-X1-Carbon-Gen-9 betterlockscreen[168557]: [*] Running prelock...
Sep 21 20:33:18 tom-ThinkPad-X1-Carbon-Gen-9 betterlockscreen[168557]: [*] Locking screen... (FAILSAFE MODE)
Sep 21 20:33:18 tom-ThinkPad-X1-Carbon-Gen-9 betterlockscreen[168557]: [*] Running postlock...
Sep 21 20:49:58 tom-ThinkPad-X1-Carbon-Gen-9 systemd[1]: [email protected]: Deactivated successfully.
Sep 21 20:49:58 tom-ThinkPad-X1-Carbon-Gen-9 systemd[1]: Started Lock screen when going to sleep/suspend.

在命令行中执行/usr/local/bin/betterlockscreen --lock会按预期锁定屏幕。

我究竟做错了什么?

答案1

我遇到了同样的问题,尝试了多种方法来解决它,但似乎都没有用。
看了这个https://bbs.archlinux.org/viewtopic.php?id=279840\ 我切换了我的显示管理器韓規模现在它运行完美。

这是betterlockscreen@$USER我使用的配置:

[Unit]
Description=Lock screen when going to sleep/suspend
Before=sleep.target
Before=suspend.target

[Service]
User=%I
Type=simple
Environment=DISPLAY=:0
ExecStart=/usr/bin/betterlockscreen --lock
TimeoutSec=infinity
ExecStartPost=/usr/bin/sleep 1

[Install]
WantedBy=sleep.target
WantedBy=suspend.target

相关内容