Define the two following units:
A unit for when the system goes to sleep.
# /etc/systemd/system/suspend@.service [Unit] Description=Suspend actions for user %I Before=sleep.target [Service] User=%i Type=forking Environment=DISPLAY=:0 ExecStart=/usr/bin/env sh /home/%i/.bin/on-suspend ExecStartPost=/usr/bin/sleep 1 [Install] WantedBy=sleep.target
And a unit for when the system resumes from sleep.
# /etc/systemd/system/resume@.service [Unit] Description=Resume actions for user %I After=suspend.target [Service] User=%i Type=simple ExecStart=/usr/bin/env sh /home/%i/.bin/on-resume [Install] WantedBy=suspend.target
Enable suspend@username and resume@username.
suspend@username
resume@username
Edit the scripts on-suspend and on-resume.
on-suspend
on-resume
See also
There was an error while loading. Please reload this page.