I am an Archlinux user, and I heavily rely on systemd for most of my userspace needs.
From time to time, I want my laptop not to suspend when I close its lid. I used to do so (DON’T, it’s the wrong way) with the following
sudo systemctl mask suspend.target
Poettering wasn’t impressed, but did not reply to explain why it’s a bad idea. It turned out I realized it myself.
When you mask a target, systemd is not able to enter it, but, as long as the condition that triggered the transition to the target persists, it tries incessantly. This causes the laptop to burn CPU cycles uselessly (with the nice fan at full throttle effect) as long as the lid is closed.
I believe the right way to do so is through logind.conf, using the right condition
HandleLidSwitchExternalPower=ignore
This allows me to have my laptop not suspending when the lid is closed AND there is an external power source connected (this is what I want when I have my laptop docked with no external monitor and I log onto it from another computer).
NOTE: systemd might not honor this setting if your DE installs an hinibitor for some event.
EDIT: systemd-inhibit
A dear friend of mine pointed out that there is a dedicated utility for this use case, systemd-inhibit. You can easily invoke it in a terminal:
systemd-inhibit sleep inf
This is surely a handy solution when you need to prevent going to suspend occasionally.