Ubuntu 15.04挂起不运行`pm-suspend`
在升级到Ubuntu GNOME 15.04(从14.10开始)之后,我注意到/etc/pm/sleep.d
中的pm-utils
挂钩在挂起/恢复时不再运行。
我有一个自定义脚本,可以在暂停之前保存亮度,并在恢复后恢复它。 如果我手动运行sudo pm-suspend
挂钩执行但如果我关闭笔记本电脑的盖子(挂起Ubuntu)脚本不会执行。 我错过了什么吗?
/etc/pm/sleep.d中的亮度脚本是(工作于14.04和14.10):
#!/bin/bash case "$1" in suspend|suspend_hybrid|hibernate) cat /sys/class/backlight/acpi_video0/brightness > /tmp/.brightness_level # modprobe -r nvidiabl ;; resume|thaw) # modprobe nvidiabl cat /tmp/.brightness_level > /sys/class/backlight/acpi_video0/brightness rm /tmp/.brightness_level ;; esac
更新 :使用systemd
找到一个更好的解决方案,没有外部脚本。 创建并启用以下服务:
[Unit] Description=Save brightness on suspend DefaultDependencies=no RequiresMountsFor=/var/lib/systemd/backlight Before=sleep.target StopWhenUnneeded=yes [Service] Type=oneshot RemainAfterExit=yes ExecStart=/lib/systemd/systemd-backlight save acpi_video0 ExecStop=/lib/systemd/systemd-backlight load acpi_video0 TimeoutSec=90s [Install] WantedBy=sleep.target
Ubuntu 16.04注意 :目标背光设备名称应以“背光:”为前缀(例如backlight:acpi_video0
)。
通过执行以下命令systemctl enable suspend-save-backlight.service
: systemctl enable suspend-save-backlight.service
(或任何你称之为的)。 请注意,acpi_video0是/sys/class/backlight
背光符号链接的名称,用于控制显示亮度,可能因系统而异。
以上使用systemd的systemd-backlight
可执行文件分别在挂起和恢复之后保存和加载亮度(灵感来自/lib/systemd/system/systemd-backlight@.service
,它在重启/启动时保存/加载亮度)。
旧解决方案 (将systemd
服务链接到我的pm-utils挂起挂钩)
发现了问题。 根据ArchWiki的这篇文章 :
当使用systemctl suspend,systemctl hibernate或systemctl hybrid-sleep时,systemd不使用pm-utils使机器进入hibernate状态; pm-utils钩子,包括任何自定义钩子 ,都不会运行。 但是,systemd提供了两种类似的机制来在这些事件上运行自定义脚本。
因此,使用systemd
(默认情况下在15.04中使用)的正确方法是创建以下服务文件,这些文件在/etc/pm/sleep.d/
执行我的亮度控制脚本,如下所示:
-
/etc/systemd/system/root-suspend.service
:[Unit] Description=Local system suspend actions Before=sleep.target [Service] Type=simple ExecStart=-/etc/pm/sleep.d/nvidiabl_brightness suspend [Install] WantedBy=sleep.target
-
/etc/systemd/system/root-resume.service
:[Unit] Description=Local system resume actions After=suspend.target [Service] Type=simple ExecStart=-/etc/pm/sleep.d/nvidiabl_brightness resume [Install] WantedBy=suspend.target
然后运行以下命令以启用这些服务:
systemctl enable root-suspend.service systemctl enable root-resume.service
有关更多详细信息,请参阅链接的文章。