Package: sleep-inhibitor
SLEEP-INHIBITORThis is a simple program to inhibit sleep/suspend onsystemdbased
Linux systems (or on compatible systems runningelogind). Some examples of the
default plugins provided are:Plugin to inhibit sleep while any audio is playing.Plugins to inhibit sleep whilePlexorJellyfinmedia server is serving media
server is serving content.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 theprovided
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-inhibitorruns 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 athttps://github.com/bulletmark/sleep-inhibitor.:warning:Warning: Unfortunately this program is currently somewhat
handicapped due tothis systemd
issue. Until this
issue is addressed, your system may not automatically [re-]suspend if
still idle after it has been inhibited, even thoughsleep-inhibitorhas removed the inhibit.MotivationWhen looking for a solution for this issue I found theautosuspendpackage 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.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.On Linux server systems, I prefer to use standardsystemdpower
management to manage sleep/suspend, configured vialogind.confandsleep.conf.These native approaches work well, and are easy to configure.Sleep-inhibitorassumes 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-inhibitorusessystemd-inhibitto execute the sleep inhibition lock.InstallationArchusers can just installsleep-inhibitorfrom the
AURthen skip to
the next Configuration section.Python 3.7 or later is required. The 3rd party ruamel.yaml package is
also required. Notesleep-inhibitoris on
PyPIso just ensure thatpipxis installed then:To install:$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/bin pipx install sleep-inhibitorTo upgrade:$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/bin pipx upgrade sleep-inhibitorTo remove:$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/bin pipx uninstall sleep-inhibitorSome plugins require other software to be installed. E.g. If you use theplex-media-serverorjellyfin-serverplugins then you must installcurl.ConfigurationTo start, copy the samplesleep-inhibitor.confconfiguration file to/etc/sleep-inhibitor.confand 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 thesample configuration
file.$ sudo cp "$(sleep-inhibitor -P)/sleep-inhibitor.conf" /etc
$ sudoedit /etc/sleep-inhibitor.confAutomatic Startup as systemd ServiceIf you installed from source or viapipthen copy the includedsleep-inhibitor.serviceto/etc/systemd/system/(note thatArchusers who installed fromAURcan 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-inhibitorIf you change the configuration file then restart with:$ sudo systemctl restart sleep-inhibitorTo see status and logs:$ systemctl status sleep-inhibitor
$ journalctl -u sleep-inhibitorPluginsTo use thestandard
pluginsdistributed with this package just specify the plugin name (i.e. the
file name) as thepathparameter in theconfiguration
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/mypluginand just specify that full path in theconfiguration
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 providedexample
pluginsdemonstrate. 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 exampleplex-media-serverplugin requires, or the process name for the exampleis-process-runningplugin.Command Line UsageTypesleep-inhibitor -hto 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 foundLicenseCopyright (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 athttps://www.gnu.org/licenses/for more details.