Skip to content

Instantly share code, notes, and snippets.

@w-vi
Created December 16, 2017 17:09
Show Gist options
  • Save w-vi/c4283607754e660b6b713310cefbde05 to your computer and use it in GitHub Desktop.
Save w-vi/c4283607754e660b6b713310cefbde05 to your computer and use it in GitHub Desktop.
User action on suspend/hybernate/resume
# /etc/systemd/system/resume@.service
[Unit]
Description=User resume actions
After=suspend.target
[Service]
User=%I
Type=simple
ExecStartPre=/usr/local/bin/ssh-connect.sh
ExecStart=/usr/bin/mysql -e 'slave start'
[Install]
WantedBy=suspend.target
# /etc/systemd/system/suspend@.service
[Unit]
Description=User suspend actions
Before=sleep.target
[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
Environment=HOME=%h
#ExecStartPre= Do whatever you need before sleep, stop some services etc
ExecStart=-/usr/bin/xscreensaver-command -lock
ExecStartPost=/usr/bin/sleep 1
[Install]
WantedBy=sleep.target
# systemctl enable suspend@<user>.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment