From: Lennart Poettering Date: Thu, 15 May 2025 12:58:07 +0000 (+0200) Subject: man: document how to hook stuff into system wakeup X-Git-Tag: v258-rc1~592 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=edecb56216c910b36980fcf590b385ede413392b;p=thirdparty%2Fsystemd.git man: document how to hook stuff into system wakeup Fixes: #6364 --- diff --git a/man/systemd.special.xml b/man/systemd.special.xml index 0195bcb7fb3..3e5e90cae85 100644 --- a/man/systemd.special.xml +++ b/man/systemd.special.xml @@ -754,12 +754,38 @@ sleep.target - A special target unit that is pulled in by - suspend.target, - hibernate.target, - suspend-then-hibernate.target, and - hybrid-sleep.target and may be used to - hook units into the sleep state logic. + A special target unit that is pulled in by suspend.target, + hibernate.target, suspend-then-hibernate.target, and + hybrid-sleep.target and may be used to hook units into the sleep state + logic. + + In order to hook external programs before the actual system sleep + operation, place their command line in a service unit file's ExecStart= line + (use Type=oneshot), and ensure the unit is pulled in by + sleep.target and ordered before it. In order to hook program code + after the actual system sleep operation (i.e. to be run after the system + woke up again), place the command in ExecStop= instead, and make sure to + enable StopWhenUnneeded= and RemainAfterExit=. Both + approaches can be combined into one unit file in order to run programs both before and after the + sleep operation. + + + Combined Example + + [Unit] +DefaultDependencies=no +StopWhenUnneeded=yes +Before=sleep.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/some-before-command +ExecStop=/Usr/bin/some-after-command + +[Install] +WantedBy=sleep.target +