On Fedora 25, my laptop's hard drive has a very low APM level (power management), so I use the udev rules from this answer to adjust it with
hdparm. However, after resuming from suspend, the APM level gets reset. Manually triggering the udev rules from the terminal works, so to automate it I tried using the following systemd service adapted from here and here:-
[Unit] Description=Re-run udev power_supply rules after resuming from suspend After=supend.target [Service] Type=oneshot User=root Group=root ExecStart=+/bin/sh -c '/usr/sbin/udevadm trigger --subsystem-match="power_supply"' [Install] WantedBy=suspend.target
I also tried combinations of
sleep.target in the
WantedBy= line, as well as
Type=simple. None of this worked, so I tried placing a script in
/etc/pm/sleep.d/, adapted from this. But this did not work either (nor did putting it in
Finally, the man page for
... scripts or binaries dropped in
/usr/lib/systemd/system-sleep/are intended for local use ... and should be considered hacks. If applications want to be notified of system suspend/hibernation and resume, there are much nicer interfaces available.
However, placing a script in
/usr/lib/systemd/system-sleep/ actually works; but in any case, what are these "much nicer interfaces" and how do I use them to either run the udev trigger (preferable) or
hdparm after resuming from suspend? Better still, is there a way to set the hard drive APM levels for on-battery and plugged-in states by means of some static configuration instead of udev rules?
Update - Fixed
The systemd service is working now. I think I mistakenly used
udevadm from the wrong directory while trying various combinations. I have posted an answer clarifying this. I apologise for any confusion caused. However, there is still the question of whether there is a way to do this statically (without udev rules).