我定义了以下内容服务到在挂起之前启动屏幕锁定器:
$ cat /etc/systemd/system/screenlock.service
[Unit]
Description=Lock X session using slock
Before=sleep.target
[Service]
User=my_user
Environment=DISPLAY=:0
ExecStart=/usr/bin/xautolock -locknow
[Install]
WantedBy=sleep.target
启动时加载:
$ systemctl status screenlock.service
● screenlock.service - Lock X session using slock
Loaded: loaded (/etc/systemd/system/screenlock.service; enabled)
Active: inactive (dead)
它在触发 RAM 挂起和恢复工作之间的某个时刻运行:
$ systemctl status screenlock.service
● screenlock.service - Lock X session using slock
Loaded: loaded (/etc/systemd/system/screenlock.service; enabled)
Active: inactive (dead)
Sep 17 08:22:22 machine systemd[1]: Starting Lock X session using slock...
Sep 17 08:22:22 machine systemd[1]: Started Lock X session using slock.
但如果它运行了前暂停时,为什么恢复时屏幕锁打开之前会看到桌面闪烁?是否Before
被sleep.target
定义为人们所期望的?是xautolock
或slock
有问题吗?
(我已经通过禁用此服务、暂停、恢复和不获取屏幕锁来验证没有其他服务干扰。)