Skip to main content

Program to run plugins to inhibit system sleep/suspend/hibernate

Project description

SLEEP-INHIBITOR

PyPi AUR

This is a simple program to inhibit sleep/suspend on systemd based Linux systems (or on compatible systems running elogind). Some examples of the default plugins provided are:

  1. Plugin to inhibit sleep while any audio is playing.

  2. Plugins to inhibit sleep while Plex or Jellyfin media server is serving media server is serving content.

  3. Plugin to inhibit sleep while a specified process is running. I use this to prevent sleep while my home backup is running.

You can also create your own custom plugins. They are extremely trivial to create as can be seen in the provided examples. A plugin can be created in shell script or any programming language. It must simply return an exit code to indicate whether the system should can be slept/suspended, or not. Sleep-inhibitor runs each plugin at the period you specify (or the default 5 minutes) and checks the result to inhibit sleep or not until at least the next check period.

The latest version of this document and code is available at https://github.com/bulletmark/sleep-inhibitor.

:warning: Warning: Unfortunately this program is currently somewhat handicapped due to this systemd issue. Until this issue is addressed, your system may not automatically [re-]suspend if still idle after it has been inhibited, even though sleep-inhibitor has removed the inhibit.

Motivation

When looking for a solution for this issue I found the autosuspend package but, in addition to providing plugins, that package also implements the complete sleep, resume, and wakeup logic. I also found the configuration and documentation confusing. I am happy with and prefer to use the native Linux sleep systems and I desired a simpler more lightweight approach that merely provided the ability to inhibit these sleep systems for some special situations.

  1. On Linux desktop systems, I prefer to use the standard GNOME power management GUI tools to automatically manage sleep/suspend (via systemd). All the major DE's provide similar GUI tools.

  2. On Linux server systems, I prefer to use standard systemd power management to manage sleep/suspend, configured via logind.conf and sleep.conf.

These native approaches work well, and are easy to configure. Sleep-inhibitor assumes you are using the native systemd based sleep facilities and merely adds the ability to add/create tiny plugins to inhibit sleep for specified conditions. Sleep-inhibitor uses systemd-inhibit to execute the sleep inhibition lock.

Installation

Arch users can just install sleep-inhibitor from the AUR then skip to the next Configuration section.

Python 3.7 or later is required. The 3rd party ruamel.yaml package is also required. Note sleep-inhibitor is on PyPI so just ensure that pipx is installed then:

To install:

$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/bin pipx install sleep-inhibitor

To upgrade:

$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/bin pipx upgrade sleep-inhibitor

To remove:

$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/bin pipx uninstall sleep-inhibitor

Some plugins require other software to be installed. E.g. If you use the plex-media-server or jellyfin-server plugins then you must install curl.

Configuration

To start, copy the sample sleep-inhibitor.conf configuration file to /etc/sleep-inhibitor.conf and then edit the sample settings in that target file to add/configure plugins to your requirements. The instructions and a description of all configuration options are fully documented in the sample configuration file.

$ sudo cp "$(sleep-inhibitor -P)/sleep-inhibitor.conf" /etc
$ sudoedit /etc/sleep-inhibitor.conf

Automatic Startup as systemd Service

If you installed from source or via pip then copy the included sleep-inhibitor.service to /etc/systemd/system/ (note that Arch users who installed from AUR can skip this first step):

$ sudo cp "$(sleep-inhibitor -P)/sleep-inhibitor.service" /etc/systemd/system/

Start sleep-indicator and enable it to automatically start at reboot with:

$ sudo systemctl enable --now sleep-inhibitor

If you change the configuration file then restart with:

$ sudo systemctl restart sleep-inhibitor

To see status and logs:

$ systemctl status sleep-inhibitor
$ journalctl -u sleep-inhibitor

Plugins

To use the standard plugins distributed with this package just specify the plugin name (i.e. the file name) as the path parameter in the configuration file. To use your own custom plugins, just specify the absolute path to that plugin. E.g. you can put your custom plugin at /home/user/bin/myplugin and just specify that full path in the configuration file.

A plugin can be any executable script/program which simply returns exit code 254 to inhibit suspend, or anything else (usually 0 of course) to not suspend. They can be very trivial to create as the provided example plugins demonstrate. A plugin can be created in any language you prefer such as Shell, Python, Ruby, C/C++, etc.

The plugin does not normally receive any arguments although you can choose to specify arbitrary arguments to any plugin via the configuration file, e.g. a sensitive token/password as the example plex-media-server plugin requires, or the process name for the example is-process-running plugin.

Command Line Usage

Type sleep-inhibitor -h to view the usage summary:

usage: sleep-inhibitor [-h] [-c CONFIG] [-p PLUGIN_DIR] [-P]

Program to run plugins to inhibit system sleep/suspend.

options:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        alternative configuration file
  -p PLUGIN_DIR, --plugin-dir PLUGIN_DIR
                        alternative plugin dir
  -P, --package-dir     just show directory where sample conf/service files,
                        and default plugins can be found

License

Copyright (C) 2020 Mark Blakeney. This program is distributed under the terms of the GNU General Public License. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at https://www.gnu.org/licenses/ for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sleep-inhibitor-1.21.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

sleep_inhibitor-1.21.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file sleep-inhibitor-1.21.1.tar.gz.

File metadata

  • Download URL: sleep-inhibitor-1.21.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for sleep-inhibitor-1.21.1.tar.gz
Algorithm Hash digest
SHA256 2bef19f995ac2ee700a44bf50d4b3036261f9a72ee4cd227dbd0a651f1974ede
MD5 d48bb3b7391471d4ce57ae0dfc03cf25
BLAKE2b-256 9e015a93409f51ac062eb3b49afcd64513921ff51b4394aa23d3a1b8fa172666

See more details on using hashes here.

File details

Details for the file sleep_inhibitor-1.21.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sleep_inhibitor-1.21.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a128093b28589d42a1f40ff084c6e40d91e06ba34dfdc7516accd3951ec42e1
MD5 e15097b86c6d7fc39b400cf9036e95b8
BLAKE2b-256 0311acdbf4dd0264d1aba7fcebcbffb6f67d570970364164e5955902e47cb4ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page