loadavgd - Monitor CPU load and terminal activity
The loadavgd program monitors the CPU load and user input at (pseudo-)
terminals. It provides a kind of power management for server systems,
where desktop environments are not available, and the common notion of
a system being idle if interactive activity is missing does not apply.
Currently, loadavgd depends on systemd components.
If the load is below a certain treshold and there is no input at any
(pseudo-) terminal for a given amount of time, a command is issued.
This command must be one of those which the session manager,
systemd-logind, understands on its DBus API, org.freedesktop.login1.
Loadavgd is configured via a configuration file, usually
/etc/loadagvd.conf. A systemd service file is provided.
COMPILATION AND INSTALLATION
Compile with
$CC -o loadavgd -O2 loadavgd.c parse_config.c sleep_systemd.c -lsystemd
Optionally, use -DDEBUG to have loadavgd output additional messages. Further
compilation and linking options might be -fpie -pie -flto.
Install,
cp loadavgd /usr/local/sbin/
cp loadavgd.conf /etc/
cp loadavgd.service /etc/systemd/system/
cp loadavgd.8.gz /usr/local/share/man/man8/
Start systemwide with
systemctl start loadavgd
Start at each following boot
systemctl enable loadavgd
Reload the configuration file,
systemctl reload loadavgd
Terminate,
systemctl stop loadavgd
Depending on the configured action, by default suspend, it might also be
possible to start loadavgd as user. It will write diagnostic messages to
stderr. Loadavgd will exit if it cannot run as ordinary user. Loadavgd
takes one argument, the location of the configuration file. If not
given, this defaults to /etc/loadavgd.conf,
./loadavgd loadavgd.conf
Reload the configuration file by sending SIGHUP to the process,
pkill -HUP loadavgd
Terminate with
pkill loadavgd
NOTES
To query terminal input, loadavgd reads the modification time of the
pseudo terminal multiplexer /dev/ptmx. User input resets the modifica‐
tion time of /dev/ptmx, but output from a program, for instance status
lines printed repeatedly from a long-running process, does not alter
any time stamp of /dev/ptmx. (In this case, the modification time of
the appropriate terminal slave, e.g., /dev/pts/0, would be updated.)