systemd suspend/resume script

Had a question the other day; a friend’s laptop would lose the trackpad after resume so his solution was to insert the module manually. Well, systemd has systemd-suspend.service which can handle those events. Details in man systemd-suspend.service

Place a script in /lib/systemd/system-sleep/ and make it executable. Any scripts in that directory will be called upon suspend (passing the parameter pre) and will be called again upon resume (passing the parameter post.) A sample script:

#!/bin/sh
if [ "${1}" = "pre" ]; then
# about to suspend …
echo "suspend event at $(date)…" > /tmp/suspend_test
elif [ "${1}" = "post" ]; then
# about to resume …
echo "resume event at $(date) …" >> /tmp/suspend_test
fi

Now, my keyboard backlight settings get saved and restored correctly on suspend/resume.

END

Leave a Reply