autosuspend.conf

Synopsis

/etc/autosuspend.conf

Description

Configures the autosuspend daemon.

Syntax

The autosuspend configuration file uses INI syntax and needs to be processable by the Python configparser module.

A simple configuration file could look like:

[general]
interval = 30
idle_time = 900
suspend_cmd = /usr/bin/systemctl suspend

[check.Ping]
enabled = false
hosts = 192.168.0.7

[check.RemoteUsers]
class = Users
enabled = true
name = .*
terminal = .*
host = [0-9].*

The configuration file consists of a [general] section, which specifies general processing options, and multiple options of the format [check.*]. These sections describe the checks to execute to determine inactivity.

General Configuration

The [general] section contains options controlling the overall behavior of the autosuspend daemon. These are:

interval

The time to wait after executing all checks in seconds.

idle_time

The required amount of time in seconds with no detected activity before the host will be suspended.

suspend_cmd

The command to execute in case the host shall be suspended. This line can contain additional command line arguments to the command to execute.

woke_up_file

Location of a file that indicates to autosuspend that the computer has suspended since the last time checks were executed. This file is usually created by a systemd service. Thus, changing the location also requires adapting the respective service. Refer to systemd integration for further details.

Check Configuration

For each check to execute, a section with the name format [check.*] needs to be created. Each check has a name and an executing class which implements the behavior. The fraction of the section name check. determines the name, and in case no class option is given inside the section, also the class which implements the check. In case the option:`class option is specified, the name is completely user-defined and the same check can even be instantiated multiple times with differing names.

For each check, these generic options can be specified:

class

Name of the class implementing the check. If this is not specified, the section name must represent a valid check class (see list below).

enabled

Needs to be true for a check to actually execute. false is assumed if not specified.

Furthermore, each check might have custom options.

Available checks

The following checks for activity are currently implemented. Each of the is described with its available configuration options and required optional dependencies.

ActiveConnection

Checks whether there is currently a client connected to a TCP server at certain ports. Can be used to e.g. block suspending the system in case SSH users are connected or a web server is used by clients.

Options

ports

list of comma-separated port numbers

Requirements

ExternalCommand

Executes an arbitrary command. In case this command returns 0, the system is assumed to be active.

The command is executed as is using shell execution. Beware of malicious commands in obtained configuration files.

Options

command

The command to execute including all arguments

Requirements

Kodi

Checks whether an instance of Kodi is currently playing.

Options

url

Base URL of the JSON RPC API of the Kodi instance, default: http://localhost:8080/jsonrpc

timeout

Request timeout in seconds, default: 5

Requirements

Load

Checks whether the system load 5 is below a certain value.

Options

threshold

a float for the maximum allowed load value, default: 2.5

Requirements

LogindSessionsIdle

Prevents suspending in case IdleHint for one of the running sessions logind sessions is set to no. Support for setting this hint currently varies greatly across display managers, screen lockers etc. Thus, check exactly whether the hint is set on your system via loginctl show-session.

Options

types

A comma-separated list of sessions types to inspect for activity. The check ignores sessions of other types. Default: tty, x11, wayland

states

A comma-separated list of session states to inspect. For instance, lingering sessions used for background programs might not be of interest. Default: active, online

Requirements

Mpd

Checks whether an instance of MPD is currently playing music.

Options

host

Host containing the MPD daemon, default: localhost

port

Port to connect to the MPD daemon, default: 6600

timeout

Request timeout in seconds, default: 5

Requirements

NetworkBandwidth

Checks whether more network bandwidth is currently being used than specified. A set of specified interfaces is checked in this regard, each of the individually, based on the average bandwidth on that interface. This average is based on the global checking interval specified in the configuration file via the interval option.

Options

interfaces

Comma-separated list of network interfaces to check

threshold_send <byte/s>

If the average sending bandwidth of one of the specified interfaces is above this threshold, then activity is detected. Specified in bytes/s, default: 100

threshold_receive <byte/s>

If the average receive bandwidth of one of the specified interfaces is above this threshold, then activity is detected. Specified in bytes/s, default: 100

Requirements

Ping

Checks whether one or more hosts answer to ICMP requests.

Options

hosts

Comma-separated list of host names or IPs.

Requirements

Processes

If currently running processes match an expression, the suspend will be blocked. You might use this to hinder the system from suspending when for example your rsync runs.

Options

processes

list of comma-separated process names to check for

Requirements

Smb

Any active Samba connection will block suspend.

Options

smbstatus

executable needs to be present.

Requirements

Users

Checks whether a user currently logged in at the system matches several criteria. All provided criteria must match to indicate activity on the host.

Options

All regular expressions are applied against the full string. Capturing substrings needs to be explicitly enabled using wildcard matching.

name

A regular expression specifying which users to capture, default: .*.

terminal

A regular expression specifying the terminal on which the user needs to be logged in, default: .*.

host

A regular expression specifying the host from which a user needs to be logged in, default: .*.

Requirements

XIdleTime

Checks whether all active local X displays have been idle for a sufficiently long time. Determining which X11 sessions currently exist on a running system is a harder problem than one might expect. Sometimes, the server runs as root, sometimes under the real user, and many other configuration variants exist. Thus, multiple sources for active X serer instances are implemented for this check, each of them having different requirements and limitations. They can be changed using the provided configuration option.

Options

timeout

required idle time in seconds

method

The method to use for acquiring running X sessions. Valid options are sockets and logind. The default is sockets.

sockets
Uses the X server sockets files found in /tmp/.X11-unix. This method requires that all X server instances run with user permissions and not as root.
logind
Uses logind to obtain the running X server instances. This does not support manually started servers.
ignore_if_process

A regular expression to match against the process names executed by each X session owner. In case the use has a running process that matches this expression, the X idle time is ignored and the check continues as if there was no activity. This can be useful in case of processes which inevitably tinker with the idle time.

ignore_users

Do not check sessions of users matching this regular expressions.

Requirements

XPath

A generic check which queries a configured URL and expected the reply to contain XML data. The returned XML document is checked against a configured XPath expression and in case the expression matches, the system is assumed to be active.

This can for instance be used with the TV streaming server tvheadend, which provides its current status via an XML reply. In case you want to prevent suspending in case there are active subscriptions or recordings, use the following XPath:

/currentload/subscriptions[number(.) > 0] | /currentload/recordings/recording

If you have a permantently running subscriber like Kodi, increase the 0 to 1. The second fragment after the | prevents suspending in case any recording is planned, even far in the future. If you want to be a bit more permissive, the second fragment could be replaced with:

/currentload/recordings/recording/status | /currentload/recordings/recording/next[number(.) < 10]

This only prevents suspending in case of active or planned recordings closer that 10 minutes.

Options

url

The URL to query for the XML reply.

xpath

The XPath query to execute. In case it returns a result, the system is assumed to be active.

timeout

Timeout for executed requests in seconds. Default: 5.

Requirements

The options of individual checks are outlined below.