Personally, I usually prefer my laptop to be suspended when I close the lid; however, there are times that I want it to keep working when I close the lid, e.g. when I'm downloading stuff.
Apparently, it is ideal to educate such applications (e.g. curl, aria2, others!) to "inhibit" suspension when they are active; but you can also inhibit suspension manually when running such things using systemd-inhibit
. For example, if I want to download something using wget
, I'll do it like this:
systemd-inhibit --what=handle-lid-switch --who="My Lid-Close-Suspend Inhibitor" --why="Downloading" --mode=block wget http://some/url/to/get
Then I can close my laptop's lid and it won't suspend while wget is running. As a bonus, it'll suspend when download finishes, which is what you won't get with above solutions which prevents suspension completely when the lid is closed (well, yes you can run pm-suspend
to suspend).
If you have multiple processes for which you want to prevent suspension, you can run each one with systemd-inhibit
, and the laptop will suspend when all inhibitors are terminated.
As another example, I've free Internet access at nights (e.g. from 1 AM to 7 AM), so I want to download stuff during this period but not after that, and I prefer that my laptop suspends in the morning (at 7 AM). Therefore, I run:
systemd-inhibit --what=handle-lid-switch --who="My Lid-Close-Suspend Inhibitor" --why="FreeInternet" --mode=block sleep 15h
And I have a cron job which will killall systemd-inhibit processes.