2

There are things I would like the laptop to do after resuming from a disk hibernation.

In particular, I have it set at the lowest CPU frequency by default, which makes it absolutely silent (no fan noise at all) but still quick enough most of the time (I change the policy with another script when I really need more computing power). But, after resuming from a disk hibernation, the default factory behavior has been restored, which is a variable frequency and the damn fan firing up here and there in order to offer me the marvelous experience of opening programs a fraction of a second faster.

Remark: If anyone is curious about the script that sets the lowest CPU in my laptop (in case there's a better way to do this that is not affected by hibertate/resume), here it is:

sudo cpufreq-set -c 0 -g userspace
sudo cpufreq-set -c 1 -g userspace
sudo cpufreq-set -c 2 -g userspace
sudo cpufreq-set -c 3 -g userspace
sudo cpufreq-set -c 0 -f 400MHz
sudo cpufreq-set -c 1 -f 400MHz
sudo cpufreq-set -c 2 -f 400MHz
sudo cpufreq-set -c 3 -f 400MHz

And, by the way, this needs to disable intel_pstate in grub, which tells me that this feature is not going to be there in the future. Why the heck Intel doesn't like to allow me to have a silent and slow computer at times if that is my will, is a mistery to me.

1 Answer 1

7

Depending on your system you may be able to put an executable script in /etc/pm/sleep.d/00mysleep which will be run with an argument saying what state is being entered: suspend, hibernate. resume, or thaw.

With systemd you should be able to put a script in, for example,
/lib/systemd/system-sleep/00myscript which will be run with 2 arguments, the first being pre when stopping and post when resuming, and the second being the state, namely suspend, hibernate, or hybrid-sleep.

Or with systemd you can create and enable a Unit such as file /etc/systemd/system/myscript.service holding

[Unit]
Description=Run myscripttorun
After=suspend.target
#After=hibernate.target
#After=hybrid-sleep.target
[Service]
ExecStart=/some/path/myscripttorun
[Install]
WantedBy=suspend.target
#WantedBy=hibernate.target
#WantedBy=hybrid-sleep.target

enabled with

sudo systemctl enable myscript.service

Choose between the appropriate suspend, hibernate, hybrid-sleep targets by removing the # on the lines, and create a suitable script /some/path/myscripttorun to be run.


See also my more detailed answer to a similar question.

4
  • if my service generally runs all the time but needs to restart after resuming from suspend, which variation of this do I want? Jan 17, 2019 at 16:50
  • If you already have a Unit set up and running, you probably can just add an extra Restart=always to the [Service] part, and it may get restarted when you come back from suspend, if it died. But you should post a new question with your specific details as it is a difficult subject in general.
    – meuh
    Jan 17, 2019 at 17:17
  • According to this, WantedBy and After being the same is contradicting. WantedBy means it is part of that service while After means it should run after that service which is obviously impossible. Sep 14, 2019 at 9:56
  • @StefanFabian There are some new, working examples on archlinux.
    – meuh
    Nov 17, 2020 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .