Update: Found a nicer solution using
systemd with no external scripts. Create and enable the following service:
Description=Save brightness on suspend
ExecStart=/lib/systemd/systemd-backlight save acpi_video0
ExecStop=/lib/systemd/systemd-backlight load acpi_video0
Ubuntu 16.04 Note: The target backlight device name should be prefixed with "backlight:" (e.g.
Enable by executing:
systemctl enable suspend-save-backlight.service (or whatever you call it). Note that acpi_video0 is the name of the backlight symlink in
/sys/class/backlight which is used to control the display brightness, might vary on different systems.
The above uses systemd's
systemd-backlight executable to save and load the brightness before suspend and after resume respectively (inspired from
/lib/systemd/system/systemd-backlight@.service which saves/loads brightness on restart/boot).
Old Solution (links a
systemd service to my pm-utils suspend hook)
Found the problem. According to this ArchWiki article:
systemd does not use pm-utils to put the machine to sleep when using systemctl suspend, systemctl hibernate or systemctl hybrid-sleep; pm-utils hooks, including any custom hooks, will not be run. However, systemd provides two similar mechanisms to run custom scripts on these events.
So the right way to do it with
systemd (which is used by default in 15.04) is to create the following service files which execute my brightness control script in
/etc/pm/sleep.d/ as follows:
Description=Local system suspend actions
Description=Local system resume actions
Then run the following to enable these services:
systemctl enable root-suspend.service
systemctl enable root-resume.service
Refer to the linked article for more details.