Ali Mohamed Ali


Main

Options

Misc.

Posts by tag

art (1) | doodle (1) | elogind (1) | emacs (1) | email (1) | gnu (2) | image (1) | linux (2) | meta (1) | script (1) | sh (1) | slackware (1) | tech (5) | test (2) | time (1) | web (1)

Modifying sleep behaviour on linux with elogind

Table of Contents

On most linux systems, elogind is responsible for sleeping and hibernation. In this article, I'll explain how to stop a device from sleeping, both on the closing of a lid, or even in general.

This is quite useful for when you are making a device run something for a long time, and want to always be able to look at the screen. On laptops, this is useful if you want to make sure that your daemons/scripts are always running even when you close the switch to keep dust away.

It's quite easy to do.

1. Sleep

You should follow any of the edit in the following sections, then restart elogind in your init system.

If you are using SystemD(Arch, Ubuntu, Debian, many others), you should write the following line in a root shell after you have edited the configuration file.

# systemctl restart elogind

If you are using SysV:

# /etc/rc.d/rc.elogind restart

If you are using OpenRC:

# rc-service elogind restart

1.1. Preventing sleep altogether

The easiest way to prevent sleep is to edit /etc/elogind/sleep.conf

[Sleep]
AllowSleep=no

You can also put this in /etc/elogind/sleep.conf.d/temporary (the name of the file can be anything, but it must be in /etc/elogind/sleep.conf.d/.

1.2. Preventing sleep on the close of a lid

Alternatively, you can write under [Login] in /etc/elogind/login.conf

[Login]
LidSwitchIgnoreInhibited=no

Which will ignore the lid switch event in any case. This prevents the default HandleLidSwitch=suspend from actually being enforced.

Alternatively, you can write the following, which provides approximately the same effect.

[Login]
HandleLidSwitch=ignore

As with the other, you can put these edits in a file in /etc/elogind/login.conf.d/ and make sure there is a line [Login] at the start of the file.

Authored by Ali Mohamed Ali <someguyshutup5@gmail.com>
Licensed under CC-BY-SA 4.0 (except where noted otherwise)
Refresh this page!