Keep Ubuntu Server running on a laptop with the lid closed?

To disable entering the sleep mode I had to edit the /etc/systemd/logind.conf file and modify the line:

#HandleLidSwitch=suspend

to

HandleLidSwitch=ignore

Additionally, ensure that the file also has this line:

LidSwitchIgnoreInhibited=no

Then restart the OS via:

sudo service systemd-logind restart

just to confirm, 14.04 LTS Server user here on a Dell X100e.

sudo apt-get install acpi-support
sudo vi /etc/default/acpi-support # and then set SUSPEND_METHODS="none"
sudo /etc/init.d/acpid restart

Instantly able to close lid, no issues.

Just posting to confirm the previous posters' solution as the only fix needed. No need (currently) to do anything else in addition to this.


Turn off laptop screen when closed

This works for me on a new install of Ubuntu Server LTS 18.04.1.

The answer from @user386160 worked great to prevent my laptop from going to sleep. But I found out that my monitor was staying on even when the lid was closed (a.k.a. generating unnecessary heat).

Here's the additional steps I took to turn off the laptop monitor when the screen was closed:

sudo apt-get install acpi-support vbetool
sudo echo "event=button/lid.*" > /etc/acpi/events/lid-button
sudo echo "action=/etc/acpi/lid.sh" >> /etc/acpi/events/lid-button
sudo touch /etc/acpi/lid.sh
sudo chmod +x /etc/acpi/lid.sh
sudo nano /etc/acpi/lid.sh

Then set the contents of the lid.sh file to the following:

#!/bin/bash

grep -q close /proc/acpi/button/lid/*/state

if [ $? = 0 ]; then
    sleep 0.2 && vbetool dpms off
fi

grep -q open /proc/acpi/button/lid/*/state

if [ $? = 0 ]; then
    vbetool dpms on
fi