-
-
Notifications
You must be signed in to change notification settings - Fork 299
Systemd
Nuttapong Punpipat edited this page Nov 17, 2022
·
2 revisions
Many time, that many situations involved things that required to be executed either/both before and after some machine power operation.
Many Surface devices and Linux workarounds also involve that.
To execute command before/after suspending/hibernating/hybrid-sleeping/suspending-then-hibernating, check this sample script:
#!/bin/bash
## REMARK:
# - above shebang is required for scripting file
# - 1st arg passed to executable file is either "pre" (mean that the entry of a power operation) or "post" (mean that the exit of a power operation)
# - 2nd arg passed to executable file is either "suspend", "hibernate", "hybrid-sleep", or "suspend-then-hibernate", depends on what power operation is operating
# - SYSTEMD_SLEEP_ACTION environment variable is helpful for "suspend-then-hibernate", it has value of either "suspend", "hibernate", or "suspend-after-failed-hibernate"
case $1 in
pre)
case $2 in
hibernate)
;;
hybrid-sleep)
;;
suspend)
;;
suspend-then-hibernate)
case $SYSTEMD_SLEEP_ACTION in
suspend)
;;
hibernate)
;;
suspend-after-failed-hibernate)
;;
esac
;;
esac
;;
post)
case $2 in
hibernate)
;;
hybrid-sleep)
;;
suspend)
;;
suspend-then-hibernate)
case $SYSTEMD_SLEEP_ACTION in
suspend)
;;
hibernate)
;;
suspend-after-failed-hibernate)
;;
esac
;;
esac
;;
esac
Save your script in /usr/lib/systemd/system-sleep/, and make it executable by root.
Note that all files inside mentioned directory could be any executable file (either native binary or any scripting file which required shebang).
For more information, see https://www.freedesktop.org/software/systemd/man/systemd-suspend.service.html
- Home
- Installation and Setup
-
Supported Devices and Features
- Surface Book 1
- Surface Book 2
- Surface Book 3
- Surface Laptop Studio
- Surface Laptop Studio 2
- Surface Laptop 1
- Surface Laptop 2
- Surface Laptop 3
- Surface Laptop 4
- Surface Laptop 5
- Surface Laptop 6
- Surface Laptop Go 1
- Surface Laptop Go 2
- Surface Laptop Go 3
- Surface Laptop SE
- Surface Go 1
- Surface Go 2
- Surface Go 3
- Surface Go 4
- Surface 3
- Surface Pro 1
- Surface Pro 2
- Surface Pro 3
- Surface Pro 4
- Surface Pro 5
- Surface Pro 6
- Surface Pro 7
- Surface Pro 7+
- Surface Pro 8
- Surface Pro 9 (Intel)
- Surface Pro 10
- Surface Studio 1
- Surface Studio 2
- Surface Studio 2+
- Surface Dock
- Device Independent Information
- Known Issues / FAQ
- Links and Associated Projects
- Testers and Contributing