Prevent suspend on laptop lid close

Hello

I’m hoping to run a homelab on an old laptop and it’s important that the system continues to run when the laptop lid is closed.

I tried disabling all options under Settings > Power Saving, then rebooted but the system still suspends when i close the lid

So I then tried adding the following options into /etc/systemd/logind.conf.d/override.conf

[Login]
HandleLidSwitch=ignore
HandleLidSwitchDocked=ignore
HandleLidSwitchExternalPower=ignore

and rebooted, but the system still suspends when i close the lid.

It’s maybe worth noting that my ‘test’ to determine if the system has suspended is by having a active RDP session connected from another device, closing the lid on the laptop, then observing that the RDP session becomes unusable/disconnects. I also just tested with an ssh connection and the connection is dropped (broken pipe).

Any suggestions for how I might get this working?

False alarm - it’s working now but i have no clue what is different to when it was not working. I did delete, then recreate the file with just the single option

[Login]
HandleLidSwitch=ignore

then rebooted and it worked. I then added back in the other 2 options and it continued to work.

I’m good for now :slight_smile:

3 Likes

If you want it to be a one-off thing like when you are just moving to another room and don’t want to have to input your password you can use this shell script instead:

~/.local/bin/no-sleep:

#!/bin/bash

echo "Inhibiting sleep on lid close. To re-enable, kill this process."
systemd-inhibit --what=handle-lid-switch \
                --why="Prevent sleep on lid close" \
                sleep infinity