Here’s a solution for forcing your MacBook to stay awake even with the lid closed.
Why would anyone want to do this? Well you might want to use your MacBook as a server in a headless configuration.
Apple has a support article about this, but it didn’t work well for me and I found this to be a more reliable solution.
Download the Insomnia kernel extension, extract it from the ZIP archive and copy it to your system extensions folder:
/bin/cp -a Insomnia_r6.kext /System/Library/Extensions /usr/sbin/chown -R root:wheel /System/Library/Extensions/Insomnia_r6.kext /sbin/kextload /System/Library/Extensions/Insomnia_r6.kext
You will only need to use the commands above the first time you use this module. After that it will load automatically on startup.
To disable MacBook sleeping: /usr/sbin/sysctl -w kern.lidsleep=1
To re-enable MacBook sleeping: /usr/sbin/sysctl -w kern.lidsleep=0
To check status: /usr/sbin/sysctl kern.lidsleep
0 = Insomnia is not active (i.e. MacBook will sleep when the lid is closed)
1 = Insomnia is active (i.e. MacBook will not sleep when the lid is closed)
-1 = Insomnia kernel module is not loaded