[systemd-devel] suspend hook as user service

Michael Hirmke mh at mike.franken.de
Fri Feb 17 18:41:00 UTC 2017


Hi,

>Hi,

>is there any way to start user service before/after suspend.target? In
>wiki.archlinux.org there are only system sleep hooks [1]. I tried to lock the

yes, but they also describe, how you can add a system service handling
special user things.

[...]

You can create a service named for example "suspend_user at .service":

------------------------< snip snip snip >-----------------------------
[Unit]
Description=User suspend actions for KDE
After=sleep.target remote-fs.target
Requires=remote-fs.target
StopWhenUnneeded=yes

[Service]
User=%I
Type=oneshot
ExecStart=...
TimeoutSec=300

[Install]
WantedBy=sleep.target
------------------------< snip snip snip >-----------------------------

And enable it with:
systemctl enable suspend_user@<user>.service.

It worked for me for a while.

A much better approach is to write a script or program listening for the
according signals "PrepareForSleep" and "PrepareForShutdown" on the dbus
interface "org.freedesktop.login1".
You can start it for example in your .bashrc or in the KDE startup
routines.


>R.H.

Bye.
Michael.
-- 
Michael Hirmke


More information about the systemd-devel mailing list