I have a (trivial) custom service which runs on resume from ACPI S3 ("suspend"), the script simply wakes up a server by WOL (Wake On LAN).

This is driven by systemd, the script resides in /etc/systemd/system/on_resume.service and was added by:

chmod +x on_resume.service
systemctl enable on_resume.service
systemctl status on_resume.service

The problem is that the script only runs when the system is put into sleep by using the "Suspend" widget in XFCE (a simple pushbutton from a menu).

If I do echo "mem" > /sys/power/state, the system also gets put into sleep, but the service does not run when the system is brought back on.

In both cases I simply push the power button to bring it back.

The question is, what is the difference between these two methods of putting the system into S3, if any? Why does systemd only run the script when using XFCE's feature?

For simplicity, assume that the script has the following simple content (this particular script was used for testing, and has the exact same problem, it is therefore a minimal version to reproduce the problem):


case "$1" in
                echo "test" > /tmp/testfile_resume

exit 0

I do lock the screen through the "power manager" of XFCE when the system is put to sleep, however, I tried turning this off, and it still works using XFCE's "Suspend" pushbutton.

I then attempted to compare syslog when using the widget and using the sys filesystem manually, but there doesn't appear to be anything there to indicate a failure or anything noteworthy that sticks out.

What is the difference?

Note that I don't really care in terms of functionality, I'm perfectly fine using a pushbutton instead of typing the command, but I want to understand why.


TL;DR: you want to use systemctl suspend.

/sys/power/state is the kernel API which XFCE ultimately calls in to.

Kernel API's do not run hook scripts themselves. Software wants to be able to hook in to run commands before suspend (as well as after resume). Therefore, the simplest approach is to have a program which runs suspend hooks, calls into the kernel, and then runs resume hooks.

This being Linux, several such programs have been written over time. systemd is currently the single most prominent one.

Technical details

XFCE, or systemctl suspend -> systemd-logind -> systemd -> systemd-sleep -> linux kernel.

It's possible to hook into this in different ways, in each of the three different links that start systemd :). Your script in /etc is run by something installed in one of the latter two. See man systemd-sleep, and man systemd.special. Unfortunately the exact ways you use these hooks are not documented very well right now. (The systemd level in particular is in need of a bit of love).

As for the first possible hook: the logind "inhibitor" system is intended for use by GUI apps. It involves receiving DBus signals.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.